View Javadoc

1   /* $Id: DumperRule.java 1102402 2011-05-12 18:03:26Z simonetripodi $
2    *
3    * Licensed to the Apache Software Foundation (ASF) under one or more
4    * contributor license agreements.  See the NOTICE file distributed with
5    * this work for additional information regarding copyright ownership.
6    * The ASF licenses this file to You under the Apache License, Version 2.0
7    * (the "License"); you may not use this file except in compliance with
8    * the License.  You may obtain a copy of the License at
9    *
10   *      http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing, software
13   * distributed under the License is distributed on an "AS IS" BASIS,
14   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15   * See the License for the specific language governing permissions and
16   * limitations under the License.
17   */
18  package org.apache.commons.digester3.plugins;
19  
20  import org.xml.sax.Attributes;
21  import org.apache.commons.digester3.Rule;
22  
23  /**
24   * Demonstrates the behaviour of the Delegate interface.
25   */
26  public class DumperRule
27      extends Rule
28  {
29      @Override
30      public void begin( String namespace, String name, Attributes attributes )
31          throws Exception
32      {
33          System.out.print( "<" );
34          System.out.print( name );
35  
36          int nAttributes = attributes.getLength();
37          for ( int i = 0; i < nAttributes; ++i )
38          {
39              String key = attributes.getQName( i );
40              String value = attributes.getValue( i );
41              System.out.print( " " );
42              System.out.print( key );
43              System.out.print( "=" );
44              System.out.print( "'" );
45              System.out.print( value );
46              System.out.print( "'" );
47          }
48          System.out.println( ">" );
49      }
50  
51      @Override
52      public void body( String namespace, String name, String text )
53          throws Exception
54      {
55          System.out.print( text );
56      }
57  
58      @Override
59      public void end( String namespace, String name )
60          throws Exception
61      {
62          System.out.print( "</" );
63          System.out.print( name );
64          System.out.println( ">" );
65      }
66  }