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/03 07:58:32 UTC
svn commit: r1130908 - in
/commons/sandbox/digester3/trunk/src/examples/xmlrules/addressbook/src/main/java/org/apache/commons/digester3/examples/xmlrules/addressbook:
Address.java AddressBook.java Main.java Person.java
Author: simonetripodi
Date: Fri Jun 3 05:58:31 2011
New Revision: 1130908
URL: http://svn.apache.org/viewvc?rev=1130908&view=rev
Log:
minor code format
Modified:
commons/sandbox/digester3/trunk/src/examples/xmlrules/addressbook/src/main/java/org/apache/commons/digester3/examples/xmlrules/addressbook/Address.java
commons/sandbox/digester3/trunk/src/examples/xmlrules/addressbook/src/main/java/org/apache/commons/digester3/examples/xmlrules/addressbook/AddressBook.java
commons/sandbox/digester3/trunk/src/examples/xmlrules/addressbook/src/main/java/org/apache/commons/digester3/examples/xmlrules/addressbook/Main.java
commons/sandbox/digester3/trunk/src/examples/xmlrules/addressbook/src/main/java/org/apache/commons/digester3/examples/xmlrules/addressbook/Person.java
Modified: commons/sandbox/digester3/trunk/src/examples/xmlrules/addressbook/src/main/java/org/apache/commons/digester3/examples/xmlrules/addressbook/Address.java
URL: http://svn.apache.org/viewvc/commons/sandbox/digester3/trunk/src/examples/xmlrules/addressbook/src/main/java/org/apache/commons/digester3/examples/xmlrules/addressbook/Address.java?rev=1130908&r1=1130907&r2=1130908&view=diff
==============================================================================
--- commons/sandbox/digester3/trunk/src/examples/xmlrules/addressbook/src/main/java/org/apache/commons/digester3/examples/xmlrules/addressbook/Address.java (original)
+++ commons/sandbox/digester3/trunk/src/examples/xmlrules/addressbook/src/main/java/org/apache/commons/digester3/examples/xmlrules/addressbook/Address.java Fri Jun 3 05:58:31 2011
@@ -22,59 +22,70 @@ import java.io.PrintStream;
/**
* See Main.java.
*/
-public class Address {
+public class Address
+{
+
private String type;
+
private String street;
+
private String city;
+
private String state;
+
private String zip;
+
private String country;
@Override
- public String toString() {
+ public String toString()
+ {
StringBuilder sb = new StringBuilder();
- sb.append( " address (type "+ type + ")\n");
- sb.append( " " + street + "\n");
- sb.append( " " + city + " " + state + " " + zip + "\n");
- sb.append( " " + country + "\n");
+ sb.append( " address (type " + type + ")\n" );
+ sb.append( " " + street + "\n" );
+ sb.append( " " + city + " " + state + " " + zip + "\n" );
+ sb.append( " " + country + "\n" );
return sb.toString();
}
- public void print(PrintStream out, int indentAmount) {
- StringBuilder indentStr = new StringBuilder(indentAmount);
- for(; indentAmount > 0; --indentAmount) {
- indentStr.append(' ');
+ public void print( PrintStream out, int indentAmount )
+ {
+ StringBuilder indentStr = new StringBuilder( indentAmount );
+ for ( ; indentAmount > 0; --indentAmount )
+ {
+ indentStr.append( ' ' );
}
-
- out.print(indentStr);
- out.print("address type: ");
- out.println(type);
-
- out.print(indentStr);
- out.println(" " + street);
-
- out.print(indentStr);
- out.println(" " + city + " " + state + " " + zip);
-
- out.print(indentStr);
- out.println(" " + country);
+
+ out.print( indentStr );
+ out.print( "address type: " );
+ out.println( type );
+
+ out.print( indentStr );
+ out.println( " " + street );
+
+ out.print( indentStr );
+ out.println( " " + city + " " + state + " " + zip );
+
+ out.print( indentStr );
+ out.println( " " + country );
}
-
+
/**
* Returns the value of street.
*/
public String getStreet()
{
- return street;
+ return street;
}
/**
* Sets the value of street.
+ *
* @param street The value to assign to street.
*/
- public void setStreet(String street)
+ public void setStreet( String street )
{
- this.street = street;
+ this.street = street;
}
/**
@@ -82,16 +93,17 @@ public class Address {
*/
public String getCity()
{
- return city;
+ return city;
}
/**
* Sets the value of city.
+ *
* @param city The value to assign to city.
*/
- public void setCity(String city)
+ public void setCity( String city )
{
- this.city = city;
+ this.city = city;
}
/**
@@ -99,16 +111,17 @@ public class Address {
*/
public String getState()
{
- return state;
+ return state;
}
/**
* Sets the value of state.
+ *
* @param state The value to assign to state.
*/
- public void setState(String state)
+ public void setState( String state )
{
- this.state = state;
+ this.state = state;
}
/**
@@ -116,16 +129,17 @@ public class Address {
*/
public String getZip()
{
- return zip;
+ return zip;
}
/**
* Sets the value of zip.
+ *
* @param zip The value to assign to zip.
*/
- public void setZip(String zip)
+ public void setZip( String zip )
{
- this.zip = zip;
+ this.zip = zip;
}
/**
@@ -133,16 +147,17 @@ public class Address {
*/
public String getCountry()
{
- return country;
+ return country;
}
/**
* Sets the value of country.
+ *
* @param country The value to assign to country.
*/
- public void setCountry(String country)
+ public void setCountry( String country )
{
- this.country = country;
+ this.country = country;
}
/**
@@ -150,17 +165,17 @@ public class Address {
*/
public String getType()
{
- return type;
+ return type;
}
/**
* Sets the value of type.
+ *
* @param type The value to assign to type.
*/
- public void setType(String type)
+ public void setType( String type )
{
- this.type = type;
+ this.type = type;
}
-}
-
+}
Modified: commons/sandbox/digester3/trunk/src/examples/xmlrules/addressbook/src/main/java/org/apache/commons/digester3/examples/xmlrules/addressbook/AddressBook.java
URL: http://svn.apache.org/viewvc/commons/sandbox/digester3/trunk/src/examples/xmlrules/addressbook/src/main/java/org/apache/commons/digester3/examples/xmlrules/addressbook/AddressBook.java?rev=1130908&r1=1130907&r2=1130908&view=diff
==============================================================================
--- commons/sandbox/digester3/trunk/src/examples/xmlrules/addressbook/src/main/java/org/apache/commons/digester3/examples/xmlrules/addressbook/AddressBook.java (original)
+++ commons/sandbox/digester3/trunk/src/examples/xmlrules/addressbook/src/main/java/org/apache/commons/digester3/examples/xmlrules/addressbook/AddressBook.java Fri Jun 3 05:58:31 2011
@@ -23,19 +23,25 @@ import java.util.Iterator;
/**
* See Main.java.
*/
-public class AddressBook {
+public class AddressBook
+{
+
LinkedList<Person> people = new LinkedList<Person>();
-
- public void addPerson(Person p) {
- people.addLast(p);
+
+ public void addPerson( Person p )
+ {
+ people.addLast( p );
}
-
- public void print() {
- System.out.println("Address book has " + people.size() + " entries");
- for(Iterator<Person> i = people.iterator(); i.hasNext(); ) {
+ public void print()
+ {
+ System.out.println( "Address book has " + people.size() + " entries" );
+
+ for ( Iterator<Person> i = people.iterator(); i.hasNext(); )
+ {
Person p = i.next();
p.print();
}
}
+
}
Modified: commons/sandbox/digester3/trunk/src/examples/xmlrules/addressbook/src/main/java/org/apache/commons/digester3/examples/xmlrules/addressbook/Main.java
URL: http://svn.apache.org/viewvc/commons/sandbox/digester3/trunk/src/examples/xmlrules/addressbook/src/main/java/org/apache/commons/digester3/examples/xmlrules/addressbook/Main.java?rev=1130908&r1=1130907&r2=1130908&view=diff
==============================================================================
--- commons/sandbox/digester3/trunk/src/examples/xmlrules/addressbook/src/main/java/org/apache/commons/digester3/examples/xmlrules/addressbook/Main.java (original)
+++ commons/sandbox/digester3/trunk/src/examples/xmlrules/addressbook/src/main/java/org/apache/commons/digester3/examples/xmlrules/addressbook/Main.java Fri Jun 3 05:58:31 2011
@@ -46,58 +46,67 @@ import java.net.URL;
* <p>
* Usage: java Main xmlrules.xml example.xml
*/
-public class Main {
-
+public class Main
+{
+
/**
* Main method : entry point for running this example program.
* <p>
* Usage: java Example example.xml
*/
- public static void main(String[] args) throws Exception {
- if (args.length != 2) {
+ public static void main( String[] args )
+ throws Exception
+ {
+ if ( args.length != 2 )
+ {
usage();
- System.exit(-1);
+ System.exit( -1 );
}
-
+
String rulesfileName = args[0];
String datafileName = args[1];
-
+
// Create a Digester instance which has been initialised with
// rules loaded from the specified file.
- URL rulesURL = ClassLoader.getSystemResource(rulesfileName);
- if (rulesURL == null) {
- System.out.println("Unable to find rules file.");
- System.exit(-1);
+ URL rulesURL = ClassLoader.getSystemResource( rulesfileName );
+ if ( rulesURL == null )
+ {
+ System.out.println( "Unable to find rules file." );
+ System.exit( -1 );
}
- Digester d = DigesterLoader.createDigester(rulesURL);
-
+ Digester d = DigesterLoader.createDigester( rulesURL );
+
// Prime the digester stack with an object for rules to
// operate on. Note that it is quite common for "this"
// to be the object pushed.
AddressBook book = new AddressBook();
- d.push(book);
-
+ d.push( book );
+
// Process the input file.
- try {
- java.io.File srcfile = new java.io.File(datafileName);
- d.parse(srcfile);
+ try
+ {
+ java.io.File srcfile = new java.io.File( datafileName );
+ d.parse( srcfile );
}
- catch(java.io.IOException ioe) {
- System.out.println("Error reading input file:" + ioe.getMessage());
- System.exit(-1);
+ catch ( java.io.IOException ioe )
+ {
+ System.out.println( "Error reading input file:" + ioe.getMessage() );
+ System.exit( -1 );
}
- catch(org.xml.sax.SAXException se) {
- System.out.println("Error parsing input file:" + se.getMessage());
- System.exit(-1);
+ catch ( org.xml.sax.SAXException se )
+ {
+ System.out.println( "Error parsing input file:" + se.getMessage() );
+ System.exit( -1 );
}
-
-
+
// Print out all the contents of the address book, as loaded from
// the input file.
book.print();
}
-
- private static void usage() {
- System.out.println("Usage: java Main xmlrules.xml example.xml");
+
+ private static void usage()
+ {
+ System.out.println( "Usage: java Main xmlrules.xml example.xml" );
}
-}
\ No newline at end of file
+
+}
Modified: commons/sandbox/digester3/trunk/src/examples/xmlrules/addressbook/src/main/java/org/apache/commons/digester3/examples/xmlrules/addressbook/Person.java
URL: http://svn.apache.org/viewvc/commons/sandbox/digester3/trunk/src/examples/xmlrules/addressbook/src/main/java/org/apache/commons/digester3/examples/xmlrules/addressbook/Person.java?rev=1130908&r1=1130907&r2=1130908&view=diff
==============================================================================
--- commons/sandbox/digester3/trunk/src/examples/xmlrules/addressbook/src/main/java/org/apache/commons/digester3/examples/xmlrules/addressbook/Person.java (original)
+++ commons/sandbox/digester3/trunk/src/examples/xmlrules/addressbook/src/main/java/org/apache/commons/digester3/examples/xmlrules/addressbook/Person.java Fri Jun 3 05:58:31 2011
@@ -25,53 +25,67 @@ import java.util.List;
/**
* See Main.java.
*/
-public class Person {
- private int id;
- private String category;
- private String name;
- private HashMap<String, String> emails = new HashMap<String, String>();
- private List<Address> addresses = new ArrayList<Address>();
-
- /**
- * A unique id for this person. Note that the Digester automatically
- * converts the id to an integer.
- */
- public void setId(int id) {
- this.id = id;
- }
-
- public void setCategory(String category) {
- this.category = category;
- }
-
- public void setName(String name) {
- this.name = name;
- }
-
- /** we assume only one email of each type... */
- public void addEmail(String type, String address) {
- emails.put(type, address);
- }
-
- public void addAddress( Address addr ) {
- addresses.add( addr );
- }
-
- public void print() {
- System.out.println("Person #" + id);
- System.out.println(" category=" + category);
- System.out.println(" name=" + name);
-
- for(Iterator<String> i = emails.keySet().iterator(); i.hasNext(); ) {
- String type = i.next();
- String address = emails.get(type);
-
- System.out.println(" email (type " + type + ") : " + address);
- }
-
- for(Iterator<Address> i = addresses.iterator(); i.hasNext(); ) {
- Address addr = i.next();
- addr.print(System.out, 2);
- }
- }
+public class Person
+{
+
+ private int id;
+
+ private String category;
+
+ private String name;
+
+ private HashMap<String, String> emails = new HashMap<String, String>();
+
+ private List<Address> addresses = new ArrayList<Address>();
+
+ /**
+ * A unique id for this person. Note that the Digester automatically converts the id to an integer.
+ */
+ public void setId( int id )
+ {
+ this.id = id;
+ }
+
+ public void setCategory( String category )
+ {
+ this.category = category;
+ }
+
+ public void setName( String name )
+ {
+ this.name = name;
+ }
+
+ /** we assume only one email of each type... */
+ public void addEmail( String type, String address )
+ {
+ emails.put( type, address );
+ }
+
+ public void addAddress( Address addr )
+ {
+ addresses.add( addr );
+ }
+
+ public void print()
+ {
+ System.out.println( "Person #" + id );
+ System.out.println( " category=" + category );
+ System.out.println( " name=" + name );
+
+ for ( Iterator<String> i = emails.keySet().iterator(); i.hasNext(); )
+ {
+ String type = i.next();
+ String address = emails.get( type );
+
+ System.out.println( " email (type " + type + ") : " + address );
+ }
+
+ for ( Iterator<Address> i = addresses.iterator(); i.hasNext(); )
+ {
+ Address addr = i.next();
+ addr.print( System.out, 2 );
+ }
+ }
+
}