You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by si...@apache.org on 2011/06/02 20:51:55 UTC

svn commit: r1130725 - in /commons/sandbox/digester3/trunk/src/examples/api/document-markup/src/main/java/org/apache/commons/digester3/examples/api/documentmarkup: Main.java MarkupDigester.java SetTextSegmentRule.java TextSegmentHandler.java

Author: simonetripodi
Date: Thu Jun  2 18:51:54 2011
New Revision: 1130725

URL: http://svn.apache.org/viewvc?rev=1130725&view=rev
Log:
code reformatted

Modified:
    commons/sandbox/digester3/trunk/src/examples/api/document-markup/src/main/java/org/apache/commons/digester3/examples/api/documentmarkup/Main.java
    commons/sandbox/digester3/trunk/src/examples/api/document-markup/src/main/java/org/apache/commons/digester3/examples/api/documentmarkup/MarkupDigester.java
    commons/sandbox/digester3/trunk/src/examples/api/document-markup/src/main/java/org/apache/commons/digester3/examples/api/documentmarkup/SetTextSegmentRule.java
    commons/sandbox/digester3/trunk/src/examples/api/document-markup/src/main/java/org/apache/commons/digester3/examples/api/documentmarkup/TextSegmentHandler.java

Modified: commons/sandbox/digester3/trunk/src/examples/api/document-markup/src/main/java/org/apache/commons/digester3/examples/api/documentmarkup/Main.java
URL: http://svn.apache.org/viewvc/commons/sandbox/digester3/trunk/src/examples/api/document-markup/src/main/java/org/apache/commons/digester3/examples/api/documentmarkup/Main.java?rev=1130725&r1=1130724&r2=1130725&view=diff
==============================================================================
--- commons/sandbox/digester3/trunk/src/examples/api/document-markup/src/main/java/org/apache/commons/digester3/examples/api/documentmarkup/Main.java (original)
+++ commons/sandbox/digester3/trunk/src/examples/api/document-markup/src/main/java/org/apache/commons/digester3/examples/api/documentmarkup/Main.java Thu Jun  2 18:51:54 2011
@@ -24,37 +24,41 @@ package org.apache.commons.digester3.exa
  * <p>
  * See the readme file included with this example for more information.
  */
- 
-public class Main {
+public class Main
+{
+
     /** The input xml to be parsed by this example. */
     String in = "<p>Hi, this is an <i>example</i> of some <b>bold</b> text.</p>";
-   
+
     /** Invoked when a text segment is present in the parsed input. */
-    public void addSegment(String text) {
-        System.out.println("Text segment: [" + text + "]");
+    public void addSegment( String text )
+    {
+        System.out.println( "Text segment: [" + text + "]" );
     }
-    
+
     /** Invoked when an &lt;i&gt; node is found in the parsed input. */
-    public void addItalic(String text) {
-        System.out.println("Italic: [" + text + "]");
+    public void addItalic( String text )
+    {
+        System.out.println( "Italic: [" + text + "]" );
     }
-    
+
     /** Invoked when an &lt;b&gt; node is found in the parsed input. */
-    public void addBold(String text) {
-        System.out.println("Bold: [" + text + "]");
+    public void addBold( String text )
+    {
+        System.out.println( "Bold: [" + text + "]" );
     }
-    
+
     /** 
      * Invoked via a standard Digester CallMethodRule, passing the 
      * "body text" of the top-level xml element. This demonstrates
      * the default behaviour of Digester (which is not suitable for
      * processing markup-style xml). 
      */
-    public void addAllText(String text) {
-        System.out.println(
-            "And the merged text for the p element is [" + text + "]");
+    public void addAllText( String text )
+    {
+        System.out.println( "And the merged text for the p element is [" + text + "]" );
     }
-    
+
     /**
      * Main method of this test harness. Set up some digester rules,
      * then parse the input xml contained in the "in" member variable.
@@ -62,27 +66,31 @@ public class Main {
      * dump information to standard output, to show the callbacks that
      * a real program could arrange to get when parsing markup input.
      */
-    public void run() throws Exception {
-        System.out.println("Started.");        
+    public void run()
+        throws Exception
+    {
+        System.out.println( "Started." );
         MarkupDigester d = new MarkupDigester();
-    
-        d.push(this);
-        
-        SetTextSegmentRule r = new SetTextSegmentRule("addSegment");
-        d.addRule("p", r);
-        d.addCallMethod("p", "addAllText", 0);
-
-        d.addCallMethod("p/i", "addItalic", 0);
-        d.addCallMethod("p/b", "addBold", 0);
-        
-        d.parse(new java.io.StringReader(in));
-        
 
-        System.out.println("Finished.");        
+        d.push( this );
+
+        SetTextSegmentRule r = new SetTextSegmentRule( "addSegment" );
+        d.addRule( "p", r );
+        d.addCallMethod( "p", "addAllText", 0 );
+
+        d.addCallMethod( "p/i", "addItalic", 0 );
+        d.addCallMethod( "p/b", "addBold", 0 );
+
+        d.parse( new java.io.StringReader( in ) );
+
+        System.out.println( "Finished." );
     }
 
-    /** See the run method. */    
-    public static void main(String[] args) throws Exception {
+    /** See the run method. */
+    public static void main( String[] args )
+        throws Exception
+    {
         new Main().run();
     }
+
 }

Modified: commons/sandbox/digester3/trunk/src/examples/api/document-markup/src/main/java/org/apache/commons/digester3/examples/api/documentmarkup/MarkupDigester.java
URL: http://svn.apache.org/viewvc/commons/sandbox/digester3/trunk/src/examples/api/document-markup/src/main/java/org/apache/commons/digester3/examples/api/documentmarkup/MarkupDigester.java?rev=1130725&r1=1130724&r2=1130725&view=diff
==============================================================================
--- commons/sandbox/digester3/trunk/src/examples/api/document-markup/src/main/java/org/apache/commons/digester3/examples/api/documentmarkup/MarkupDigester.java (original)
+++ commons/sandbox/digester3/trunk/src/examples/api/document-markup/src/main/java/org/apache/commons/digester3/examples/api/documentmarkup/MarkupDigester.java Thu Jun  2 18:51:54 2011
@@ -34,21 +34,25 @@ import org.xml.sax.Attributes;
  * <p>
  * See the readme file included with this example for more information.
  */
- 
-public class MarkupDigester extends Digester {
+public class MarkupDigester
+    extends Digester
+{
 
     /** See equivalent constructor in Digester class. */
-    public MarkupDigester() {
+    public MarkupDigester()
+    {
     }
 
     /** See equivalent constructor in Digester class. */
-    public MarkupDigester(SAXParser parser) {
-        super(parser);
+    public MarkupDigester( SAXParser parser )
+    {
+        super( parser );
     }
 
     /** See equivalent constructor in Digester class. */
-    public MarkupDigester(XMLReader reader) {
-        super(reader);
+    public MarkupDigester( XMLReader reader )
+    {
+        super( reader );
     }
 
     //===================================================================
@@ -69,11 +73,11 @@ public class MarkupDigester extends Dige
      * @exception SAXException if a parsing error is to be reported
      */
     @Override
-    public void characters(char buffer[], int start, int length)
-            throws SAXException {
-
-        super.characters(buffer, start, length);
-        currTextSegment.append(buffer, start, length);
+    public void characters( char buffer[], int start, int length )
+        throws SAXException
+    {
+        super.characters( buffer, start, length );
+        currTextSegment.append( buffer, start, length );
     }
 
     /**
@@ -89,20 +93,18 @@ public class MarkupDigester extends Dige
      *   no attributes, it shall be an empty Attributes object. 
      * @exception SAXException if a parsing error is to be reported
      */
- 
     @Override
-    public void startElement(String namespaceURI, String localName,
-                             String qName, Attributes list)
-            throws SAXException {
-
+    public void startElement( String namespaceURI, String localName, String qName, Attributes list )
+        throws SAXException
+    {
         handleTextSegments();
 
         // Unlike bodyText, which accumulates despite intervening child
         // elements, currTextSegment gets cleared here. This means that
         // we don't need to save it on a stack either.
-        currTextSegment.setLength(0);
+        currTextSegment.setLength( 0 );
 
-        super.startElement(namespaceURI, localName, qName, list);
+        super.startElement( namespaceURI, localName, qName, list );
     }
 
     /**
@@ -118,13 +120,13 @@ public class MarkupDigester extends Dige
      * @exception SAXException if a parsing error is to be reported
      */
     @Override
-    public void endElement(String namespaceURI, String localName,
-                           String qName) throws SAXException {
- 
+    public void endElement( String namespaceURI, String localName, String qName )
+        throws SAXException
+    {
         handleTextSegments();
-        currTextSegment.setLength(0);
-        super.endElement(namespaceURI, localName, qName);
-     }
+        currTextSegment.setLength( 0 );
+        super.endElement( namespaceURI, localName, qName );
+    }
 
     /**
      * Iterate over the list of rules most recently matched, and
@@ -132,22 +134,31 @@ public class MarkupDigester extends Dige
      * invoke that rule's textSegment method passing the current
      * segment of text from the xml element body.
      */
-    private void handleTextSegments() throws SAXException {    
-        if (currTextSegment.length() > 0) {
+    private void handleTextSegments()
+        throws SAXException
+    {
+        if ( currTextSegment.length() > 0 )
+        {
             String segment = currTextSegment.toString();
             List parentMatches = (List) matches.peek();
             int len = parentMatches.size();
-            for(int i=0; i<len; ++i) {
-                Rule r = (Rule) parentMatches.get(i);
-                if (r instanceof TextSegmentHandler) {
+            for ( int i = 0; i < len; ++i )
+            {
+                Rule r = (Rule) parentMatches.get( i );
+                if ( r instanceof TextSegmentHandler )
+                {
                     TextSegmentHandler h = (TextSegmentHandler) r;
-                    try {
-                        h.textSegment(segment);
-                    } catch(Exception e) {
-                        throw createSAXException(e);
+                    try
+                    {
+                        h.textSegment( segment );
+                    }
+                    catch ( Exception e )
+                    {
+                        throw createSAXException( e );
                     }
                 }
             }
         }
     }
+
 }

Modified: commons/sandbox/digester3/trunk/src/examples/api/document-markup/src/main/java/org/apache/commons/digester3/examples/api/documentmarkup/SetTextSegmentRule.java
URL: http://svn.apache.org/viewvc/commons/sandbox/digester3/trunk/src/examples/api/document-markup/src/main/java/org/apache/commons/digester3/examples/api/documentmarkup/SetTextSegmentRule.java?rev=1130725&r1=1130724&r2=1130725&view=diff
==============================================================================
--- commons/sandbox/digester3/trunk/src/examples/api/document-markup/src/main/java/org/apache/commons/digester3/examples/api/documentmarkup/SetTextSegmentRule.java (original)
+++ commons/sandbox/digester3/trunk/src/examples/api/document-markup/src/main/java/org/apache/commons/digester3/examples/api/documentmarkup/SetTextSegmentRule.java Thu Jun  2 18:51:54 2011
@@ -24,19 +24,20 @@ import org.apache.commons.digester3.Rule
  * When a text segment is discovered, it calls a specific method on the top
  * object on the stack.
  */
-
-public class SetTextSegmentRule extends Rule implements TextSegmentHandler {
-
+public class SetTextSegmentRule
+    extends Rule
+    implements TextSegmentHandler
+{
 
     // ----------------------------------------------------------- Constructors
 
-    public SetTextSegmentRule(String methodName) {
+    public SetTextSegmentRule( String methodName )
+    {
         this.methodName = methodName;
     }
 
     // ----------------------------------------------------- Instance Variables
 
-
     /**
      * The method name to call on the parent object.
      */
@@ -47,13 +48,15 @@ public class SetTextSegmentRule extends 
     /**
      * Process the end of this element.
      */
-    public void textSegment(String text) throws Exception {
+    public void textSegment( String text )
+        throws Exception
+    {
 
-        Object target = getDigester().peek(0);
+        Object target = getDigester().peek( 0 );
 
         // Call the specified method
-        Class paramTypes[] = new Class[] {String.class};
-        MethodUtils.invokeMethod(target, methodName,
-            new Object[]{ text }, paramTypes);
+        Class paramTypes[] = new Class[] { String.class };
+        MethodUtils.invokeMethod( target, methodName, new Object[] { text }, paramTypes );
     }
+
 }

Modified: commons/sandbox/digester3/trunk/src/examples/api/document-markup/src/main/java/org/apache/commons/digester3/examples/api/documentmarkup/TextSegmentHandler.java
URL: http://svn.apache.org/viewvc/commons/sandbox/digester3/trunk/src/examples/api/document-markup/src/main/java/org/apache/commons/digester3/examples/api/documentmarkup/TextSegmentHandler.java?rev=1130725&r1=1130724&r2=1130725&view=diff
==============================================================================
--- commons/sandbox/digester3/trunk/src/examples/api/document-markup/src/main/java/org/apache/commons/digester3/examples/api/documentmarkup/TextSegmentHandler.java (original)
+++ commons/sandbox/digester3/trunk/src/examples/api/document-markup/src/main/java/org/apache/commons/digester3/examples/api/documentmarkup/TextSegmentHandler.java Thu Jun  2 18:51:54 2011
@@ -15,13 +15,16 @@ package org.apache.commons.digester3.exa
  * 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.
- */ 
+ */
 
 /**
- * Public interface for any Rule subclass which is interested in handling
- * text segments as well as the complete body text.
+ * Public interface for any Rule subclass which is interested in handling text segments as well as the complete body
+ * text.
  */
+public interface TextSegmentHandler
+{
+
+    public void textSegment( String text )
+        throws Exception;
 
-public interface TextSegmentHandler {
-    public void textSegment(String text) throws Exception;
 }