Filewatcher File Search
FTP Search
  
Directory (beta)
  
Content Search (beta)
   
pkg://jakarta-commons-digester-1.6-2jpp_4fc.src.rpm:259175/commons-digester-1.6-src.tar.gz  info  downloads

commons-digester-1.6-src/0040755000076600007660000000000010117664673016257 5ustar  crazybullcrazybullcommons-digester-1.6-src/src/0040755000076600007660000000000010117664667017051 5ustar  crazybullcrazybullcommons-digester-1.6-src/src/conf/0040755000076600007660000000000010117664655017773 5ustar  crazybullcrazybullcommons-digester-1.6-src/src/conf/MANIFEST.MF0100644000076600007660000000046310041652064021410 0ustar  crazybullcrazybullExtension-Name: org.apache.commons.digester
Specification-Title: "Jakarta Commons Digester"
Specification-Vendor: "Apache Software Foundation"
Specification-Version: "1.6"
Implementation-Title: "org.apache.commons.digester"
Implementation-Vendor: "Apache Software Foundation"
Implementation-Version: "1.6"

commons-digester-1.6-src/src/examples/0040755000076600007660000000000010117664660020660 5ustar  crazybullcrazybullcommons-digester-1.6-src/src/examples/api/0040755000076600007660000000000010117664656021436 5ustar  crazybullcrazybullcommons-digester-1.6-src/src/examples/api/addressbook/0040755000076600007660000000000010117664656023736 5ustar  crazybullcrazybullcommons-digester-1.6-src/src/examples/api/addressbook/.cvsignore0100644000076600007660000000001007735526045025723 0ustar  crazybullcrazybull*.class
commons-digester-1.6-src/src/examples/api/addressbook/AddressBook.java0100644000076600007660000000212410040207031026744 0ustar  crazybullcrazybull/*
 * Copyright 2003-2004 The Apache Software Foundation.
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *      http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * 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.
 */ 

import java.util.LinkedList;
import java.util.Iterator;

/**
 * See Main.java.
 */
public class AddressBook {
    LinkedList people = new LinkedList();
    
    public void addPerson(Person p) {
        people.addLast(p);
    }
    
    public void print() {
        System.out.println("Address book has " + people.size() + " entries");

        for(Iterator i = people.iterator(); i.hasNext(); ) {
            Person p = (Person) i.next();
            p.print();
        }
    }
}
commons-digester-1.6-src/src/examples/api/addressbook/Main.java0100644000076600007660000001251410040206652025444 0ustar  crazybullcrazybull/*
 * Copyright 2003-2004 The Apache Software Foundation.
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *      http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * 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.
 */ 

import org.apache.commons.digester.Digester;

/**
 * A simple program to demonstrate the basic functionality of the
 * Commons Digester module.
 * <p>
 * This code will parse the provided "example.xml" file to build a tree
 * of java objects, then cause those objects to print out their values
 * to demonstrate that the input file has been processed correctly.
 * <p>
 * As with all code, there are many ways of achieving the same goal;
 * the solution here is only one possible solution to the problem.
* <p> 
 * Very verbose comments are included here, as this class is intended
 * as a tutorial; if you look closely at method "addRules", you will
 * see that the amount of code required to use the Digester is actually
 * quite low.
 * <p>
 * Usage: java Main example.xml
 */
public class Main {
    
    /**
     * Main method : entry point for running this example program.
     * <p>
     * Usage: java Example example.xml
     */
    public static void main(String[] args) {
        if (args.length != 1) {
            usage();
            System.exit(-1);
        }
        
        String filename = args[0];
        
        // Create a Digester instance
        Digester d = new Digester();
        
        // 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);
        
        // Add rules to the digester that will be triggered while
        // parsing occurs.
        addRules(d);
        
        // Process the input file.
        try {
            java.io.File srcfile = new java.io.File(filename);
            d.parse(srcfile);
        }
        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);
        }
        
        
        // Print out all the contents of the address book, as loaded from
        // the input file.
        book.print();
    }
    
    private static void addRules(Digester d) {

        //--------------------------------------------------        
        // when we encounter a "person" tag, do the following:

        // create a new instance of class Person, and push that
        // object onto the digester stack of objects
        d.addObjectCreate("address-book/person", Person.class);
        
        // map *any* attributes on the tag to appropriate
        // setter-methods on the top object on the stack (the Person
        // instance created by the preceeding rule). 
        //
        // For example:
        // if attribute "id" exists on the xml tag, and method setId 
        // with one parameter exists on the object that is on top of
        // the digester object stack, then a call will be made to that
        // method. The value will be type-converted from string to
        // whatever type the target method declares (where possible), 
        // using the commons ConvertUtils functionality.
        //
        // Attributes on the xml tag for which no setter methods exist
        // on the top object on the stack are just ignored.
        d.addSetProperties("address-book/person");

        // call the addPerson method on the second-to-top object on
        // the stack (the AddressBook object), passing the top object
        // on the stack (the recently created Person object).
        d.addSetNext("address-book/person", "addPerson");        
        
        //--------------------------------------------------        
        // when we encounter a "name" tag, call setName on the top
        // object on the stack, passing the text contained within the
        // body of that name element [specifying a zero parameter count
        // implies one actual parameter, being the body text]. 
        // The top object on the stack will be a person object, because 
        // the pattern address-book/person always triggers the 
        // ObjectCreateRule we added previously.
        d.addCallMethod("address-book/person/name", "setName", 0);
        
        //--------------------------------------------------        
        // when we encounter an "email" tag, call addEmail on the top
        // object on the stack, passing two parameters: the "type"
        // attribute, and the text within the tag body.
        d.addCallMethod("address-book/person/email", "addEmail", 2);
        d.addCallParam("address-book/person/email", 0, "type");
        d.addCallParam("address-book/person/email", 1);
    }

    private static void usage() {
        System.out.println("Usage: java Main example.xml");
    }
}commons-digester-1.6-src/src/examples/api/addressbook/Person.java0100644000076600007660000000332210040207031026013 0ustar  crazybullcrazybull/*
 * Copyright 2001-2004 The Apache Software Foundation.
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *      http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * 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.
 */ 

import java.util.HashMap;
import java.util.Iterator;

/**
 * See Main.java.
 */
public class Person {
  private int id;
  private String category;
  private String name;
  private HashMap emails = new HashMap();
  
  /** 
   * 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 print() {
      System.out.println("Person #" + id);
      System.out.println("  category=" + category);
      System.out.println("  name=" + name);
      
      for(Iterator i = emails.keySet().iterator(); i.hasNext(); ) {
          String type = (String) i.next();
          String address = (String) emails.get(type);
          
          System.out.println("  email (type " + type + ") : " + address);
      }
  }
}
commons-digester-1.6-src/src/examples/api/addressbook/build.xml0100644000076600007660000001104010110732434025527 0ustar  crazybullcrazybull<!--
 Copyright 2004 The Apache Software Foundation.
  
 Licensed under the Apache License, Version 2.0 (the "License");
 you may not use this file except in compliance with the License.
 You may obtain a copy of the License at
  
      http://www.apache.org/licenses/LICENSE-2.0
  
 Unless required by applicable law or agreed to in writing, software
 distributed under the License is distributed on an "AS IS" BASIS,
 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.
-->

<project name="Example-AddressBook" default="compile" basedir=".">


<!-- ========== Initialize Properties ===================================== -->


  <property file="build.properties"/>                <!-- Component local   -->
  <property file="../build.properties"/>             <!-- examples/api local-->
  <property file="../../../../build.properties"/>    <!-- Digester local     -->
  <property file="../../../../../build.properties"/> <!-- Commons local     -->
  <property file="${user.home}/build.properties"/>   <!-- User local        -->


<!-- ========== External Dependencies ===================================== -->


  <!-- The directories corresponding to your necessary dependencies -->
  <property name="jaxp.home"               value="/usr/local/jaxp1.1"/>
  <property name="commons.home"            value="../../../../.."/>
  <property name="beanutils.home"          value="${commons.home}/beanutils"/>
  <property name="collections.home"        value="${commons.home}/collections"/>
  <property name="logging.home"            value="${commons.home}/logging"/>
  <property name="digester.home"            value="${commons.home}/digester"/>


<!-- ========== Derived Values ============================================ -->


  <!-- The locations of necessary jar files -->
  <property name="jaxp.jaxp.jar"           value="${jaxp.home}/jaxp.jar"/>
  <property name="jaxp.parser.jar"         value="${jaxp.home}/crimson.jar"/>
  <property name="commons-beanutils.jar"   value="${beanutils.home}/dist/commons-beanutils.jar"/>
  <property name="commons-collections.jar" value="${collections.home}/dist/commons-collections.jar"/>
  <property name="commons-logging.jar"     value="${logging.home}/dist/commons-logging.jar"/>
  <property name="commons-digester.jar"     value="${digester.home}/dist/commons-digester.jar"/>


<!-- ========== Component Declarations ==================================== -->

  <!-- The name of this component -->
  <property name="component.name"          value="addressbook"/>


<!-- ========== Compiler Defaults ========================================= -->

  <!-- Should Java compilations set the 'debug' compiler option? -->
  <property name="compile.debug"           value="true"/>

  <!-- Should Java compilations set the 'deprecation' compiler option? -->
  <property name="compile.deprecation"     value="false"/>

  <!-- Should Java compilations set the 'optimize' compiler option? -->
  <property name="compile.optimize"        value="true"/>

  <!-- Construct compile classpath -->
  <path id="compile.classpath">
    <pathelement location="."/>
    <pathelement location="${jaxp.jaxp.jar}"/>
    <pathelement location="${jaxp.parser.jar}"/>
    <pathelement location="${commons-beanutils.jar}"/>
    <pathelement location="${commons-collections.jar}"/>
    <pathelement location="${commons-logging.jar}"/>
    <pathelement location="${commons-digester.jar}"/>
  </path>


<!-- ========== Executable Targets ======================================== -->


  <target name="compile">
    <javac  srcdir="."
           destdir="."
             debug="${compile.debug}"
       deprecation="${compile.deprecation}"
          optimize="${compile.optimize}">
      <classpath refid="compile.classpath"/>
    </javac>
  </target>


  <target name="clean">
    <delete>
      <fileset dir="." includes="*.class"/>
    </delete>
    <delete dir="docs"/>
  </target>

  <target name="all" depends="clean,compile"/>

  <target name="javadoc" depends="compile">
    <mkdir      dir="docs"/>
    <javadoc destdir="docs"
                 author="true"
                private="true"
                version="true">
      <classpath  refid="compile.classpath"/>
      <fileset dir="." includes="*.java"/>
    </javadoc>
  </target>

  <target name="run" depends="compile">
    <java classname="Main" fork="yes">
      <arg value="example.xml"/>
      <classpath refid="compile.classpath"/>
      <classpath>
        <pathelement location="."/>
      </classpath>
    </java>
  </target>
</project>
commons-digester-1.6-src/src/examples/api/addressbook/example.xml0100644000076600007660000000165110110732434026072 0ustar  crazybullcrazybull<!--
 Copyright 2004 The Apache Software Foundation.
  
 Licensed under the Apache License, Version 2.0 (the "License");
 you may not use this file except in compliance with the License.
 You may obtain a copy of the License at
  
      http://www.apache.org/licenses/LICENSE-2.0
  
 Unless required by applicable law or agreed to in writing, software
 distributed under the License is distributed on an "AS IS" BASIS,
 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.
-->

<address-book>
  <person id="1" category="acquaintance">
    <name>Gonzo</name>
    <email type="business">gonzo@muppets.com</email>
  </person>

  <person id="2" category="rolemodel">
    <name>Kermit</name>
    <email type="business">kermit@muppets.com</email>
    <email type="home">kermie@acme.com</email>
  </person>

</address-book>commons-digester-1.6-src/src/examples/api/addressbook/readme.txt0100644000076600007660000000341410110732434025712 0ustar  crazybullcrazybull#########################################################################
# Copyright 2004 The Apache Software Foundation.
#  
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#  
#      http://www.apache.org/licenses/LICENSE-2.0
#  
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# 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.
#########################################################################

== overview

The files in this directory are intended as an example of how to use
the Apache Digester's basic functionality via its java interface.

Topics covered:
* how to create a digester instance
* how to parse a file
* how to use the "object create" rule to create java objects
* how to use the "set properties" rule (basic usage) to map xml attributes
  to java bean properties.
* how to use the "set next" rule to build trees of java objects.
* how to use the "call method rule" (basic usage)
* how to use the "call parameter rule" to process the text contained
  in a tag's body
* how to use the "call parameter rule" to process the contents of an 
  xml attribute.

== compiling and running

First rename the build.properties.sample file in the parent directory
to build.properties and edit it to suit your environment. Then in this
directory:

* to compile:
  ant compile

* to run:
  ant run

Alternatively, you can set up your CLASSPATH appropriately, and
run the example directly. See the build.properties and build.xml
files for details.
commons-digester-1.6-src/src/examples/api/.cvsignore0100644000076600007660000000001007735526031023416 0ustar  crazybullcrazybull*.class
commons-digester-1.6-src/src/examples/api/build.properties.sample0100644000076600007660000000210610110732434026106 0ustar  crazybullcrazybull#####################################################
# Copyright 2004 The Apache Software Foundation.
#  
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#  
#      http://www.apache.org/licenses/LICENSE-2.0
#  
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# 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.
####################################################

# 
# Example build properties
# 
# Copy this to build.properties and then edit the properties to 
# provide local references.
#


myjars=/home/me/jakarta-commons-jars

commons-beanutils.jar=${myjars}/commons-beanutils.jar
commons-collections.jar=${myjars}/commons-collections.jar
commons-logging.jar=${myjars}/commons-logging.jar
commons-digester.jar=${myjars}/commons-digester.jar


commons-digester-1.6-src/src/examples/api/build.xml0100644000076600007660000000602510110732434023236 0ustar  crazybullcrazybull<!--
 Copyright 2004 The Apache Software Foundation.
  
 Licensed under the Apache License, Version 2.0 (the "License");
 you may not use this file except in compliance with the License.
 You may obtain a copy of the License at
  
      http://www.apache.org/licenses/LICENSE-2.0
  
 Unless required by applicable law or agreed to in writing, software
 distributed under the License is distributed on an "AS IS" BASIS,
 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.
-->
<!-- 
*******************************************************
API Examples Script
===================
Provides helpful services to get folks up and running
the examples quickly.

* Compile - compiles all the examples to the directories
in which the their source files reside.

* Run - runs each example in turn. 

Note: 
These examples will only build and run if the 
rights jars are in the classpath. The classpath
can be set by copying the build.properties.sample file
in this directory to build.properties and then setting
the properties appropriately. Or by editing the 
build.properties file (based on the build.properties.sample
file in CVS) so that it contains absolute paths.

Note:
build.xml files are provided in each subdirectory. This
provide similar fuctionality for each example individually.

Note:
The examples are graduated. It is best to look at them 
in order. Please consult the documentation for more details.

*******************************************************
-->
<project name="Examples" default="about" basedir=".">
    
  <target name='about'>
    <echo>
*******************************************************
API Examples Script
===================
Provides helpful services to get folks up and running
the examples quickly.

* Compile - compiles all the examples to the directories
in which the their source files reside.

* Run - runs each example in turn. 

Note: 
These examples will only build and run if the 
rights jars are in the classpath. The classpath
can be set by copying the build.properties.sample file
in this directory to build.properties and then setting
the properties appropriately. Or by editing the 
build.properties file (based on the build.properties.sample
file in CVS) so that it contains absolute paths.

Note:
build.xml files are provided in each subdirectory. This
provide similar fuctionality for each example individually.

Note:
The examples are graduated. It is best to look at them 
in order. Please consult the documentation for more details.

*******************************************************
    </echo>
  </target>

  <target name="compile">
    <ant dir="addressbook" target="compile"/>
    <ant dir="catalog" target="compile"/>
  </target>

  <target name="run" depends="compile">
    <ant dir="addressbook" target="compile"/>
    <ant dir="catalog" target="compile"/>
  </target>
  
  <target name="clean">
    <ant dir="addressbook" target="clean"/>
    <ant dir="catalog" target="clean"/>
  </target>

</project>
commons-digester-1.6-src/src/examples/api/readme.txt0100644000076600007660000000255010110732434023412 0ustar  crazybullcrazybull#########################################################################
# Copyright 2004 The Apache Software Foundation.
#  
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#  
#      http://www.apache.org/licenses/LICENSE-2.0
#  
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# 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.
#########################################################################

The subdirectories of this directory provide examples of how to use
the Apache Digester's java API.

With the API approach, java code is used to configure the digester with
a set of rules to execute when xml is processed. It is these rules that
determine how the input xml is mapped into a tree of java objects.

An alternative is to use the "xmlrules" digester extension, which allows
the digester rules to be configured via an xml file. This allows the
mapping between input xml and java objects to be modified without
recompilation of any source code.

The examples are graduated in the following order:

1. addressbook
2. catalogcommons-digester-1.6-src/src/examples/api/catalog/0040755000076600007660000000000010117664656023050 5ustar  crazybullcrazybullcommons-digester-1.6-src/src/examples/api/catalog/.cvsignore0100644000076600007660000000001007735526061025033 0ustar  crazybullcrazybull*.class
commons-digester-1.6-src/src/examples/api/catalog/AudioVisual.java0100644000076600007660000000347610040207772026132 0ustar  crazybullcrazybull/*
 * Copyright 2003-2004 The Apache Software Foundation.
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *      http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * 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.
 */ 
 
/**
 *  See Main.java.
 */
 
public class AudioVisual implements Item {

    private int yearMade;
    private String category;
    private String name;
    private String desc;
    private Integer runtime;
    private String type;

    // note: digester can convert a string in the xml file to an int.
    public void setYearMade(int yearMade) {
        this.yearMade = yearMade;
    }

    public void setCategory(String category) {
        this.category = category;
    }

    public void setName(String name) {
        this.name = name;
    }

    public void setDesc(String desc) {
        this.desc = desc;
    }

    // note: digester can convert a string in the xml file to an Integer
    public void setRuntime(Integer runtime) {
        this.runtime = runtime;
    }

    public void setType(String type) {
        this.type = type;
    }

    public void print() {
        System.out.println("AudioVisual:");
        System.out.println("  type=" + type);
        System.out.println("  yearMade=" + yearMade);
        System.out.println("  category=" + category);
        System.out.println("  name=" + name);
        System.out.println("  desc=" + desc);
        System.out.println("  runtime=" + runtime);
    }
}

commons-digester-1.6-src/src/examples/api/catalog/Book.java0100644000076600007660000000243210040207772024566 0ustar  crazybullcrazybull/*
 * Copyright 2003-2004 The Apache Software Foundation.
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *      http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * 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.
 */ 

/**
 * See Main.java.
 */
public class Book implements Item {
	
  private String isbn;
  private String title;
  private String author;
  private String desc;

  public Book(String isbn) {
	  this.isbn = isbn;
  }
  
  public void setTitle(String title) {
      this.title = title;
  }
  
  public void setAuthor(String author) {
      this.author = author;
  }
  
  public void setDesc(String desc) {
      this.desc = desc;
  }
  
  public void print() {
      System.out.println("Book:");
      System.out.println("  isbn=" + isbn);
      System.out.println("  title=" + title);
      System.out.println("  author=" + author);
      System.out.println("  desc=" + desc);
  }
}
commons-digester-1.6-src/src/examples/api/catalog/BookFactory.java0100644000076600007660000000521510040207772026120 0ustar  crazybullcrazybull/*
 * Copyright 2003-2004 The Apache Software Foundation.
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *      http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * 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.
 */ 

import org.apache.commons.digester.AbstractObjectCreationFactory;

/**
 * The Book class doesn't have a no-argument constructor, so the
 * standard digester ObjectCreateRule can't be used to create instances
 * of it.
 * <p>
 * To resolve this issue, the FactoryCreateRule can be used in 
 * conjunction with an appropriate factory class, like this one.
 * The "createObject" method of the factory is invoked to generate
 * object instances when required.
 * <p>
 * The factory object can access any xml attributes, plus of course
 * any values set up within it before digester parsing starts (like
 * JNDI references, database connections, etc) that it may in the
 * process of generating an appropriate object.
 * <p>
 * Note that it is <i>not</i> possible for any data to be extracted
 * from the body or subelements of the xml element that caused the
 * createObject method on this factory to be invoked. For example:
 * <pre>
 *  [book isdn="12345"]
 * </pre>
 * is fine; the isdn value can be accessed during the createObject method.
 * However, given the xml:
 * <pre>
 * [book]
 *   [isdn]12345[/isdn]
 *   ...
 * </pre>
 * it is not possible to access the isdn number until after the
 * Book instance has been created.
 * <p>
 * Note that even if the class to be created does have a default constructor,
 * you may wish to use a factory class, in order to initialise the created
 * object in specific ways, or insert created objects into a central
 * register, etc.
 * <p>
 * And don't forget, either, that factories may be implemented as
 * inner classes or anonymous classes if appropriate, reducing the
 * overhead of using this functionality in many cases. 
 */
public class BookFactory extends AbstractObjectCreationFactory {
	
	public Object createObject(org.xml.sax.Attributes attributes) 
    throws Exception {
        String isbn = attributes.getValue("isbn");
        
        if (isbn == null) {
            throw new Exception(
                "Mandatory isbn attribute not present on book tag.");
        }
        
        return new Book(isbn);
	}
}
commons-digester-1.6-src/src/examples/api/catalog/Catalog.java0100644000076600007660000000211610040207772025245 0ustar  crazybullcrazybull/*
 * Copyright 2003-2004 The Apache Software Foundation.
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *      http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * 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.
 */ 

import java.util.LinkedList;
import java.util.Iterator;

/**
 * See Main.java.
 */
public class Catalog {
    LinkedList items = new LinkedList();
    
    public void addItem(Item item) {
        items.addLast(item);
    }
    
    public void print() {
        System.out.println("This catalog has " + items.size() + " items");

        for(Iterator i = items.iterator(); i.hasNext(); ) {
            Item item = (Item) i.next();
            item.print();
        }
    }
}
commons-digester-1.6-src/src/examples/api/catalog/Item.java0100644000076600007660000000127410040207772024575 0ustar  crazybullcrazybull/*
 * Copyright 2003-2004 The Apache Software Foundation.
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *      http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * 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.
 */ 

/**
 * See Main.java.
 */
public interface Item {
	public void print();
}
commons-digester-1.6-src/src/examples/api/catalog/Main.java0100644000076600007660000002211110040207551024547 0ustar  crazybullcrazybull/*
 * Copyright 2003-2004 The Apache Software Foundation.
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *      http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * 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.
 */ 

import org.apache.commons.digester.Digester;
import org.apache.commons.digester.AbstractObjectCreationFactory;

/**
 * A simple program to demonstrate some of the functionality of the
 * Commons Digester module.
 * <p>
 * This code will parse the provided "example.xml" file to build a tree
 * of java objects, then cause those objects to print out their values
 * to demonstrate that the input file has been processed correctly. The
 * input file represents a catalog of items in a library.
 * <p>
 * As with all code, there are many ways of achieving the same goal;
 * the solution here is only one possible implementation.
* <p> 
 * Very verbose comments are included here, as this class is intended
 * as a tutorial; if you look closely at method "addRules", you will
 * see that the amount of code required to use the Digester is actually
 * quite low.
 * <p>
 * Usage: java Main example.xml
 */
public class Main {
    
    /**
     * Main method : entry point for running this example program.
     * <p>
     * Usage: java CatalogDigester example.xml
     */
    public static void main(String[] args) {
        if (args.length != 1) {
            usage();
            System.exit(-1);
        }
        
        String filename = args[0];
        
        // Create a Digester instance
        Digester d = new Digester();
        
        // Add rules to the digester that will be triggered while
        // parsing occurs.
        addRules(d);
        
        // Process the input file.
        try {
            java.io.Reader reader = getInputData(filename);
            d.parse(reader);
        }
        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);
        }

        // Get the first object created by the digester's rules
        // (the "root" object). Note that this is exactly the same object
        // returned by the Digester.parse method; either approach works.
        Catalog catalog = (Catalog) d.getRoot();
        
        // Print out all the contents of the catalog, as loaded from
        // the input file.
        catalog.print();
    }
    
    private static void addRules(Digester d) {

        //--------------------------------------------------

        // when we encounter the root "catalog" tag, create an
        // instance of the Catalog class. 
        //
        // Note that this approach is different from the approach taken in 
        // the AddressBook example, where an initial "root" object was 
        // explicitly created and pushed onto the digester stack before 
        // parsing started instead
        //
        // Either approach is fine.
        
        d.addObjectCreate("catalog", Catalog.class);
        
        //--------------------------------------------------

        // when we encounter a book tag, we want to create a Book
        // instance. However the Book class doesn't have a default
        // constructor (one with no arguments), so we can't use
        // the ObjectCreateRule. Instead, we use the FactoryCreateRule.
        
        BookFactory factory = new BookFactory();
        d.addFactoryCreate("catalog/book", factory);
        
        // and add the book to the parent catalog object (which is
        // the next-to-top object on the digester object stack).
        d.addSetNext("catalog/book", "addItem");
        
        // we want each subtag of book to map the text contents of
        // the tag into a bean property with the same name as the tag.
        // eg <title>foo</title> --> setTitle("foo")
        d.addSetNestedProperties("catalog/book");
        
        
        //-----------------------------------------------
        
        // We are using the "AudioVisual" class to represent both
        // dvds and videos, so when the "dvd" tag is encountered,
        // create an AudioVisual object.
        
        d.addObjectCreate("catalog/dvd", AudioVisual.class);
        
        // add this dvd to the parent catalog object
        
        d.addSetNext("catalog/dvd", "addItem");
        
        // We want to map every xml attribute onto a corresponding
        // property-setter method on the Dvd class instance. However
        // this doesn't work with the xml attribute "year-made", because
        // of the internal hyphen. We could use explicit CallMethodRule
        // rules instead, or use a version of the SetPropertiesRule that
        // allows us to override any troublesome mappings...
        //
        // If there was more than one troublesome mapping, we could
        // use the method variant that takes arrays of xml-attribute-names
        // and bean-property-names to override multiple mappings.
        //
        // For any attributes not explicitly mapped here, the default
        // processing is applied, so xml attribute "category" --> setCategory.
        
        d.addSetProperties("catalog/dvd", "year-made", "yearMade");
        
        // We also need to tell this AudioVisual object that it is actually
        // a dvd; we can use the ObjectParamRule to pass a string to any
        // method. This usage is a little artificial - normally in this
        // situation there would be separate Dvd and Video classes.
        // Note also that equivalent behaviour could be implemented by
        // using factory objects to create & initialise the AudioVisual
        // objects with their type rather than using ObjectCreateRule.
        
        d.addCallMethod("catalog/dvd", "setType", 1);
        d.addObjectParam("catalog/dvd", 0, "dvd"); // pass literal "dvd" string
        
        // Each tag of form "<attr id="foo" value="bar"/> needs to map
        // to a call to setFoo("bar").
        //
        // This is an alternative to the syntax used for books above (see
        // method addSetNestedProperties), where the name of the subtag 
        // indicated which property to set. Using this syntax in the xml has 
        // advantages and disadvantages both for the user and the application 
        // developer. It is commonly used with the FactoryCreateRule variant 
        // which allows the target class to be created to be specified in an 
        // xml attribute; this feature of FactoryCreateRule is not demonstrated
        // in this example, but see the Apache Tomcat configuration files for 
        // an example of this usage.
        //
        // Note that despite the name similarity, there is no link
        // between SetPropertyRule and SetPropertiesRule.
        
        d.addSetProperty("catalog/dvd/attr", "id", "value");
        
        //-----------------------------------------------
        
        // and here we repeat the dvd rules, but for the video tag.
        d.addObjectCreate("catalog/video", AudioVisual.class);
        d.addSetNext("catalog/video", "addItem");
        d.addSetProperties("catalog/video", "year-made", "yearMade");
        d.addCallMethod("catalog/video", "setType", 1);
        d.addObjectParam("catalog/video", 0, "video");
        d.addSetProperty("catalog/video/attr", "id", "value");
    }

    /*
     * Reads the specified file into memory, and returns a StringReader
     * object which reads from that in-memory buffer.
     * <p>
     * This method exists just to demonstrate that the input to the
     * digester doesn't need to be from a file; for example, xml could
     * be read from a database or generated dynamically; any old buffer
     * in memory can be processed by the digester.
     * <p>
     * Clearly, if the data is always coming from a file, then calling
     * the Digester.parse method that takes a File object would be
     * more sensible (see AddressBook example).
     */
    private static java.io.Reader getInputData(String filename) 
    throws java.io.IOException {
        java.io.File srcfile = new java.io.File(filename);
        
        java.io.ByteArrayOutputStream baos = new java.io.ByteArrayOutputStream(1000);
        byte[] buf = new byte[100];
        java.io.FileInputStream fis = new java.io.FileInputStream(srcfile);
        for(;;) {
            int nread = fis.read(buf);
            if (nread == -1) {
                break;
            }
            baos.write(buf, 0, nread);
        }
        fis.close();
        
        return new java.io.StringReader( baos.toString() );
        
    }
    
    private static void usage() {
        System.out.println("Usage: java Main example.xml");
    }
}commons-digester-1.6-src/src/examples/api/catalog/build.xml0100644000076600007660000001102710110732435024647 0ustar  crazybullcrazybull<!--
 Copyright 2004 The Apache Software Foundation.
  
 Licensed under the Apache License, Version 2.0 (the "License");
 you may not use this file except in compliance with the License.
 You may obtain a copy of the License at
  
      http://www.apache.org/licenses/LICENSE-2.0
  
 Unless required by applicable law or agreed to in writing, software
 distributed under the License is distributed on an "AS IS" BASIS,
 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.
-->
<project name="Example-Catalog" default="compile" basedir=".">


<!-- ========== Initialize Properties ===================================== -->


  <property file="build.properties"/>                <!-- Component local   -->
  <property file="../build.properties"/>             <!-- examples/api local-->
  <property file="../../../../build.properties"/>    <!-- Digetser local -->
  <property file="../../../../../build.properties"/> <!-- Commons local     -->
  <property file="${user.home}/build.properties"/>   <!-- User local        -->


<!-- ========== External Dependencies ===================================== -->


  <!-- The directories corresponding to your necessary dependencies -->
  <property name="jaxp.home"               value="/usr/local/jaxp1.1"/>
  <property name="commons.home"            value="../../../../.."/>
  <property name="beanutils.home"          value="${commons.home}/beanutils"/>
  <property name="collections.home"        value="${commons.home}/collections"/>
  <property name="logging.home"            value="${commons.home}/logging"/>
  <property name="digester.home"            value="${commons.home}/digester"/>


<!-- ========== Derived Values ============================================ -->


  <!-- The locations of necessary jar files -->
  <property name="jaxp.jaxp.jar"           value="${jaxp.home}/jaxp.jar"/>
  <property name="jaxp.parser.jar"         value="${jaxp.home}/crimson.jar"/>
  <property name="commons-beanutils.jar"   value="${beanutils.home}/dist/commons-beanutils.jar"/>
  <property name="commons-collections.jar" value="${collections.home}/dist/commons-collections.jar"/>
  <property name="commons-logging.jar"     value="${logging.home}/dist/commons-logging.jar"/>
  <property name="commons-digester.jar"     value="${digester.home}/dist/commons-digester.jar"/>


<!-- ========== Component Declarations ==================================== -->

  <!-- The name of this component -->
  <property name="component.name"          value="addressbook"/>


<!-- ========== Compiler Defaults ========================================= -->

  <!-- Should Java compilations set the 'debug' compiler option? -->
  <property name="compile.debug"           value="true"/>

  <!-- Should Java compilations set the 'deprecation' compiler option? -->
  <property name="compile.deprecation"     value="false"/>

  <!-- Should Java compilations set the 'optimize' compiler option? -->
  <property name="compile.optimize"        value="true"/>

  <!-- Construct compile classpath -->
  <path id="compile.classpath">
    <pathelement location="."/>
    <pathelement location="${jaxp.jaxp.jar}"/>
    <pathelement location="${jaxp.parser.jar}"/>
    <pathelement location="${commons-beanutils.jar}"/>
    <pathelement location="${commons-collections.jar}"/>
    <pathelement location="${commons-logging.jar}"/>
    <pathelement location="${commons-digester.jar}"/>
  </path>


<!-- ========== Executable Targets ======================================== -->


  <target name="compile">
    <javac  srcdir="."
           destdir="."
             debug="${compile.debug}"
       deprecation="${compile.deprecation}"
          optimize="${compile.optimize}">
      <classpath refid="compile.classpath"/>
    </javac>
  </target>


  <target name="clean">
    <delete>
      <fileset dir="." includes="*.class"/>
    </delete>
    <delete dir="docs"/>
  </target>

  <target name="all" depends="clean,compile"/>

  <target name="javadoc" depends="compile">
    <mkdir      dir="docs"/>
    <javadoc destdir="docs"
                 author="true"
                private="true"
                version="true">
      <classpath  refid="compile.classpath"/>
      <fileset dir="." includes="*.java"/>
    </javadoc>
  </target>

  <target name="run" depends="compile">
    <java classname="Main" fork="yes">
      <arg value="example.xml"/>
      <classpath refid="compile.classpath"/>
      <classpath>
        <pathelement location="."/>
      </classpath>
    </java>
  </target>
</project>
commons-digester-1.6-src/src/examples/api/catalog/example.xml0100644000076600007660000000266610110732435025214 0ustar  crazybullcrazybull<!--
 Copyright 2004 The Apache Software Foundation.
  
 Licensed under the Apache License, Version 2.0 (the "License");
 you may not use this file except in compliance with the License.
 You may obtain a copy of the License at
  
      http://www.apache.org/licenses/LICENSE-2.0
  
 Unless required by applicable law or agreed to in writing, software
 distributed under the License is distributed on an "AS IS" BASIS,
 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.
-->

<!-- catalogue of items in a library. -->

<catalog>
  <book isbn="0-596-00184-3">
    <title>Ant, The Definitive Guide</title>
    <author>Jesse Tilly &amp; Eric M. Burke</author>
    <desc>Complete build management for Java.</desc>
  </book>

  <book isbn="0201310058">
    <title>Effective Java</title>
    <author>Joshua Bloch</author>
    <desc>Tips for experienced Java software developers.</desc>
  </book>

  <dvd category="martial arts" year-made="1978">
    <attr id="name" value="Drunken Master"/>
    <attr id="desc" value="Hilarious slapstick starring Jackie Chan."/>
    <attr id="runtime" value="106"/>
  </dvd>

  <video category="drama" year-made="1993">
    <attr id="name" value="The Piano"/>
    <attr id="desc" value="Character drama set in New Zealand during the Victorian era."/>
    <attr id="runtime" value="121"/>
  </video>

</catalog>
commons-digester-1.6-src/src/examples/api/catalog/readme.txt0100644000076600007660000000370110110732435025024 0ustar  crazybullcrazybull#########################################################################
# Copyright 2004 The Apache Software Foundation.
#  
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#  
#      http://www.apache.org/licenses/LICENSE-2.0
#  
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# 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.
#########################################################################
== overview

The files in this directory are intended as an example of how to use
the Apache Digester's basic functionality via its java interface.

Topics covered:
* how to read xml from a string (instead of a file)
* how to use Digester.getRoot() to retrieve the "root" object
  created when parsing an input file.
* how to use the "factory create" rule to create java objects which
  do not have default (no-argument) constructors.
* how to use the "set properties" rule (advanced usage) to map xml attributes
  to java bean properties with names different from the xml attribute name.
* how to use the SetPropertyRule.
* how to use the ObjectParamRule to pass a constant string to a method.


If you haven't read the "addressbook" example, it is recommended that
you start there first. This example demonstrates more advanced features
of the digester.

== compiling and running


First rename the build.properties.sample file in the parent directory
to build.properties and edit it to suit your environment. Then in this
directory:

* to compile:
  ant compile

* to run:
  ant run

Alternatively, you can set up your CLASSPATH appropriately, and
run the example directly. See the build.properties and build.xml
files for details.
commons-digester-1.6-src/src/examples/api/document-markup/0040755000076600007660000000000010117664656024551 5ustar  crazybullcrazybullcommons-digester-1.6-src/src/examples/api/document-markup/Main.java0100644000076600007660000000572110040200332026246 0ustar  crazybullcrazybull/*
 * Copyright 2004 The Apache Software Foundation.
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *      http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * 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.
 */ 

/** 
 * A simple "test harness" which demonstrates how the MarkupDigester class
 * (plus the supporting interface/rule classes) can process "document-markup"
 * style xml data.
 * <p>
 * See the readme file included with this example for more information.
 */
 
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 + "]");
    }
    
    /** Invoked when an &lt;i&gt; node is found in the parsed input. */
    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 + "]");
    }
    
    /** 
     * 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 + "]");
    }
    
    /**
     * Main method of this test harness. Set up some digester rules,
     * then parse the input xml contained in the "in" member variable.
     * The rules cause methods on this object to be invoked, which just
     * 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.");        
        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.");        
    }

    /** See the run method. */    
    public static void main(String[] args) throws Exception {
        new Main().run();
    }
}
commons-digester-1.6-src/src/examples/api/document-markup/MarkupDigester.java0100644000076600007660000001262610040200332030312 0ustar  crazybullcrazybull/*
 * Copyright 2004 The Apache Software Foundation.
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *      http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * 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.
 */ 

import org.apache.commons.digester.Digester;
import org.apache.commons.digester.Rule;

import java.util.List;
import javax.xml.parsers.SAXParser;
import org.xml.sax.XMLReader;
import org.xml.sax.SAXException;
import org.xml.sax.Attributes;

/**
 * This is a subclass of digester which supports rules which implement
 * the TextSegmentHandler interface, causing the "textSegment" method
 * on each matching rule (of the appropriate type) to be invoked when
 * an element contains a segment of text followed by a child element.
 * <p>
 * See the readme file included with this example for more information.
 */
 
public class MarkupDigester extends Digester {

    /** See equivalent constructor in Digester class. */
    public MarkupDigester() {
    }

    /** See equivalent constructor in Digester class. */
    public MarkupDigester(SAXParser parser) {
        super(parser);
    }

    /** See equivalent constructor in Digester class. */
    public MarkupDigester(XMLReader reader) {
        super(reader);
    }

    //===================================================================

    /**
     * The text found in the current element since the last child element.
     */
    protected StringBuffer currTextSegment = new StringBuffer();

    /**
     * Process notification of character data received from the body of
     * an XML element.
     *
     * @param buffer The characters from the XML document
     * @param start Starting offset into the buffer
     * @param length Number of characters from the buffer
     *
     * @exception SAXException if a parsing error is to be reported
     */
    public void characters(char buffer[], int start, int length)
            throws SAXException {

        super.characters(buffer, start, length);
        currTextSegment.append(buffer, start, length);
    }

    /**
     * Process notification of the start of an XML element being reached.
     *
     * @param namespaceURI The Namespace URI, or the empty string if the element
     *   has no Namespace URI or if Namespace processing is not being performed.
     * @param localName The local name (without prefix), or the empty
     *   string if Namespace processing is not being performed.
     * @param qName The qualified name (with prefix), or the empty
     *   string if qualified names are not available.
     * @param list The attributes attached to the element. If there are
     *   no attributes, it shall be an empty Attributes object. 
     * @exception SAXException if a parsing error is to be reported
     */
 
    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);

        super.startElement(namespaceURI, localName, qName, list);
    }

    /**
     * Process notification of the end of an XML element being reached.
     *
     * @param namespaceURI - The Namespace URI, or the empty string if the
     *   element has no Namespace URI or if Namespace processing is not
     *   being performed.
     * @param localName - The local name (without prefix), or the empty
     *   string if Namespace processing is not being performed.
     * @param qName - The qualified XML 1.0 name (with prefix), or the
     *   empty string if qualified names are not available.
     * @exception SAXException if a parsing error is to be reported
     */
    public void endElement(String namespaceURI, String localName,
                           String qName) throws SAXException {
 
        handleTextSegments();
        currTextSegment.setLength(0);
        super.endElement(namespaceURI, localName, qName);
     }

    /**
     * Iterate over the list of rules most recently matched, and
     * if any of them implement the TextSegmentHandler interface then
     * 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) {
            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) {
                    TextSegmentHandler h = (TextSegmentHandler) r;
                    try {
                        h.textSegment(segment);
                    } catch(Exception e) {
                        throw createSAXException(e);
                    }
                }
            }
        }
    }
}
commons-digester-1.6-src/src/examples/api/document-markup/SetTextSegmentRule.java0100644000076600007660000000326010040200332031131 0ustar  crazybullcrazybull/*
 * Copyright 2004 The Apache Software Foundation.
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *      http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * 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.
 */ 

import org.apache.commons.beanutils.MethodUtils;
import org.apache.commons.digester.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 {


    // ----------------------------------------------------------- Constructors

    public SetTextSegmentRule(String methodName) {
        this.methodName = methodName;
    }

    // ----------------------------------------------------- Instance Variables


    /**
     * The method name to call on the parent object.
     */
    protected String methodName = null;

    // --------------------------------------------------------- Public Methods

    /**
     * Process the end of this element.
     */
    public void textSegment(String text) throws Exception {

        Object target = digester.peek(0);

        // Call the specified method
        Class paramTypes[] = new Class[] {String.class};
        MethodUtils.invokeMethod(target, methodName,
            new Object[]{ text }, paramTypes);
    }
}
commons-digester-1.6-src/src/examples/api/document-markup/TextSegmentHandler.java0100644000076600007660000000152710040200332031127 0ustar  crazybullcrazybull/*
 * Copyright 2004 The Apache Software Foundation.
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *      http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * 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 TextSegmentHandler {
    public void textSegment(String text) throws Exception;
}
commons-digester-1.6-src/src/examples/api/document-markup/build.xml0100644000076600007660000001076410110732435026357 0ustar  crazybullcrazybull<!--
 Copyright 2004 The Apache Software Foundation.
  
 Licensed under the Apache License, Version 2.0 (the "License");
 you may not use this file except in compliance with the License.
 You may obtain a copy of the License at
  
      http://www.apache.org/licenses/LICENSE-2.0
  
 Unless required by applicable law or agreed to in writing, software
 distributed under the License is distributed on an "AS IS" BASIS,
 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.
-->
<project name="Example-Markup" default="compile" basedir=".">


<!-- ========== Initialize Properties ===================================== -->


  <property file="build.properties"/>                <!-- Component local   -->
  <property file="../build.properties"/>             <!-- examples/api local-->
  <property file="../../../../build.properties"/>    <!-- Digester local     -->
  <property file="../../../../../build.properties"/> <!-- Commons local     -->
  <property file="${user.home}/build.properties"/>   <!-- User local        -->


<!-- ========== External Dependencies ===================================== -->


  <!-- The directories corresponding to your necessary dependencies -->
  <property name="jaxp.home"               value="/usr/local/jaxp1.1"/>
  <property name="commons.home"            value="../../../../.."/>
  <property name="beanutils.home"          value="${commons.home}/beanutils"/>
  <property name="collections.home"        value="${commons.home}/collections"/>
  <property name="logging.home"            value="${commons.home}/logging"/>
  <property name="digester.home"            value="${commons.home}/digester"/>


<!-- ========== Derived Values ============================================ -->


  <!-- The locations of necessary jar files -->
  <property name="jaxp.jaxp.jar"           value="${jaxp.home}/jaxp.jar"/>
  <property name="jaxp.parser.jar"         value="${jaxp.home}/crimson.jar"/>
  <property name="commons-beanutils.jar"   value="${beanutils.home}/dist/commons-beanutils.jar"/>
  <property name="commons-collections.jar" value="${collections.home}/dist/commons-collections.jar"/>
  <property name="commons-logging.jar"     value="${logging.home}/dist/commons-logging.jar"/>
  <property name="commons-digester.jar"     value="${digester.home}/dist/commons-digester.jar"/>


<!-- ========== Component Declarations ==================================== -->

  <!-- The name of this component -->
  <property name="component.name"          value="markup"/>


<!-- ========== Compiler Defaults ========================================= -->

  <!-- Should Java compilations set the 'debug' compiler option? -->
  <property name="compile.debug"           value="true"/>

  <!-- Should Java compilations set the 'deprecation' compiler option? -->
  <property name="compile.deprecation"     value="false"/>

  <!-- Should Java compilations set the 'optimize' compiler option? -->
  <property name="compile.optimize"        value="true"/>

  <!-- Construct compile classpath -->
  <path id="compile.classpath">
    <pathelement location="."/>
    <pathelement location="${jaxp.jaxp.jar}"/>
    <pathelement location="${jaxp.parser.jar}"/>
    <pathelement location="${commons-beanutils.jar}"/>
    <pathelement location="${commons-collections.jar}"/>
    <pathelement location="${commons-logging.jar}"/>
    <pathelement location="${commons-digester.jar}"/>
  </path>


<!-- ========== Executable Targets ======================================== -->


  <target name="compile">
    <javac  srcdir="."
           destdir="."
             debug="${compile.debug}"
       deprecation="${compile.deprecation}"
          optimize="${compile.optimize}">
      <classpath refid="compile.classpath"/>
    </javac>
  </target>


  <target name="clean">
    <delete>
      <fileset dir="." includes="*.class"/>
    </delete>
    <delete dir="docs"/>
  </target>

  <target name="all" depends="clean,compile"/>

  <target name="javadoc" depends="compile">
    <mkdir      dir="docs"/>
    <javadoc destdir="docs"
                 author="true"
                private="true"
                version="true">
      <classpath  refid="compile.classpath"/>
      <fileset dir="." includes="*.java"/>
    </javadoc>
  </target>

  <target name="run" depends="compile">
    <java classname="Main" fork="yes">
      <classpath refid="compile.classpath"/>
      <classpath>
        <pathelement location="."/>
      </classpath>
    </java>
  </target>
</project>
commons-digester-1.6-src/src/examples/api/document-markup/readme.txt0100644000076600007660000000502110110732436026523 0ustar  crazybullcrazybull#########################################################################
# Copyright 2004 The Apache Software Foundation.
#  
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#  
#      http://www.apache.org/licenses/LICENSE-2.0
#  
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# 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.
#########################################################################

== overview

The files in this directory are intended as an example of how to use
the Apache Digester to parse "document-markup" style xml. It also serves as an
example of how to subclass the main Digester class in order to extend
its functionality.

By "document-markup" xml, we mean input like XHTML, where the data is valid
xml and where some elements contain interleaved text and child elements.

For example, "<p>Hi, <i>this</i> is some <b>document-style</b> xml.</p>"

Topics covered:
* how to subclass digester
* how to process markup-style xml.

== compiling and running

First rename the build.properties.sample file in the parent directory
to build.properties and edit it to suit your environment. Then in this
directory:

* to compile:
  ant compile

* to run:
  ant run

Alternatively, you can set up your CLASSPATH appropriately, and
run the example directly. See the build.properties and build.xml
files for details.

== Notes

The primary use of the Digester is to process xml configuration files.
Such files do not typically interleave text and child elements in the
style encountered with document markup. The standard Digester behaviour is 
therefore to accumulate all text within an xml element's body (of which there is
expected to be only one "segment") and present it to a Rule or user method
as a single string.

While this significantly simplifies the implementation of Rule classes for
the primary Digester goal of parsing configuration files, this process of
simplifying all text within an element into a single string "loses" critical
information necessary to correctly parse "document-markup" xml.

This example shows one method of extending the Digester class to resolve
this issue..

At some time the ability to process "document-markup" style xml may be built 
into the standard Digester class.
commons-digester-1.6-src/src/examples/rss/0040755000076600007660000000000010117664657021475 5ustar  crazybullcrazybullcommons-digester-1.6-src/src/examples/rss/src/0040755000076600007660000000000010117664657022264 5ustar  crazybullcrazybullcommons-digester-1.6-src/src/examples/rss/src/conf/0040755000076600007660000000000010117664657023211 5ustar  crazybullcrazybullcommons-digester-1.6-src/src/examples/rss/src/conf/MANIFEST.MF0100644000076600007660000000050710045005073024617 0ustar  crazybullcrazybullExtension-Name: org.apache.commons.digester.rss
Specification-Title: "Jakarta Commons Digester RSS Example"
Specification-Vendor: "Apache Software Foundation"
Specification-Version: "1.6"
Implementation-Title: "org.apache.commons.digester.rss"
Implementation-Vendor: "Apache Software Foundation"
Implementation-Version: "1.6"

commons-digester-1.6-src/src/examples/rss/src/java/0040755000076600007660000000000010117664657023205 5ustar  crazybullcrazybullcommons-digester-1.6-src/src/examples/rss/src/java/org/0040755000076600007660000000000010117664657023774 5ustar  crazybullcrazybullcommons-digester-1.6-src/src/examples/rss/src/java/org/apache/0040755000076600007660000000000010117664657025215 5ustar  crazybullcrazybullcommons-digester-1.6-src/src/examples/rss/src/java/org/apache/commons/0040755000076600007660000000000010117664657026670 5ustar  crazybullcrazybullcommons-digester-1.6-src/src/examples/rss/src/java/org/apache/commons/digester/0040755000076600007660000000000010117664657030476 5ustar  crazybullcrazybullcommons-digester-1.6-src/src/examples/rss/src/java/org/apache/commons/digester/rss/0040755000076600007660000000000010117664660031277 5ustar  crazybullcrazybullcommons-digester-1.6-src/src/examples/rss/src/java/org/apache/commons/digester/rss/Channel.java0100644000076600007660000003430110045005073033473 0ustar  crazybullcrazybull/*
 * Copyright 2001-2004 The Apache Software Foundation.
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *      http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * 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.
 */ 


package org.apache.commons.digester.rss;

import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.io.Serializable;
import java.io.UnsupportedEncodingException;
import java.io.Writer;
import java.util.ArrayList;


/**
 * <p>Implementation object representing a <strong>channel</strong> in the
 * <em>Rich Site Summary</em> DTD, version 0.91.  This class may be subclassed
 * to further specialize its behavior.</p>
 */

public class Channel implements Serializable {


    // ----------------------------------------------------- Instance Variables


    /**
     * The set of items associated with this Channel.
     */
    protected ArrayList items = new ArrayList();


    /**
     * The set of skip days for this channel.
     */
    protected ArrayList skipDays = new ArrayList();


    /**
     * The set of skip hours for this channel.
     */
    protected ArrayList skipHours = new ArrayList();


    // ------------------------------------------------------------- Properties


    /**
     * The channel copyright (1-100 characters).
     */
    protected String copyright = null;

    public String getCopyright() {
        return (this.copyright);
    }

    public void setCopyright(String copyright) {
        this.copyright = copyright;
    }


    /**
     * The channel description (1-500 characters).
     */
    protected String description = null;

    public String getDescription() {
        return (this.description);
    }

    public void setDescription(String description) {
        this.description = description;
    }


    /**
     * The channel description file URL (1-500 characters).
     */
    protected String docs = null;

    public String getDocs() {
        return (this.docs);
    }

    public void setDocs(String docs) {
        this.docs = docs;
    }


    /**
     * The image describing this channel.
     */
    protected Image image = null;

    public Image getImage() {
        return (this.image);
    }

    public void setImage(Image image) {
        this.image = image;
    }


    /**
     * The channel language (2-5 characters).
     */
    protected String language = null;

    public String getLanguage() {
        return (this.language);
    }

    public void setLanguage(String language) {
        this.language = language;
    }


    /**
     * The channel last build date (1-100 characters).
     */
    protected String lastBuildDate = null;

    public String getLastBuildDate() {
        return (this.lastBuildDate);
    }

    public void setLastBuildDate(String lastBuildDate) {
        this.lastBuildDate = lastBuildDate;
    }


    /**
     * The channel link (1-500 characters).
     */
    protected String link = null;

    public String getLink() {
        return (this.link);
    }

    public void setLink(String link) {
        this.link = link;
    }


    /**
     * The managing editor (1-100 characters).
     */
    protected String managingEditor = null;

    public String getManagingEditor() {
        return (this.managingEditor);
    }

    public void setManagingEditor(String managingEditor) {
        this.managingEditor = managingEditor;
    }


    /**
     * The channel publication date (1-100 characters).
     */
    protected String pubDate = null;

    public String getPubDate() {
        return (this.pubDate);
    }

    public void setPubDate(String pubDate) {
        this.pubDate = pubDate;
    }


    /**
     * The channel rating (20-500 characters).
     */
    protected String rating = null;

    public String getRating() {
        return (this.rating);
    }

    public void setRating(String rating) {
        this.rating = rating;
    }


    /**
     * The text input description for this channel.
     */
    protected TextInput textInput = null;

    public TextInput getTextInput() {
        return (this.textInput);
    }

    public void setTextInput(TextInput textInput) {
        this.textInput = textInput;
    }


    /**
     * The channel title (1-100 characters).
     */
    protected String title = null;

    public String getTitle() {
        return (this.title);
    }

    public void setTitle(String title) {
        this.title = title;
    }


    /**
     * The RSS specification version number used to create this Channel.
     */
    protected double version = 0.91;

    public double getVersion() {
        return (this.version);
    }

    public void setVersion(double version) {
        this.version = version;
    }


    /**
     * The webmaster email address (1-100 characters).
     */
    protected String webMaster = null;

    public String getWebMaster() {
        return (this.webMaster);
    }

    public void setWebMaster(String webMaster) {
        this.webMaster = webMaster;
    }


    // --------------------------------------------------------- Public Methods


    /**
     * Add an additional item.
     *
     * @param item The item to be added
     */
    public void addItem(Item item) {
        synchronized (items) {
            items.add(item);
        }
    }


    /**
     * Add an additional skip day name.
     *
     * @param skipDay The skip day to be added
     */
    public void addSkipDay(String skipDay) {
        synchronized (skipDays) {
            skipDays.add(skipDay);
        }
    }


    /**
     * Add an additional skip hour name.
     *
     * @param skipHour The skip hour to be added
     */
    public void addSkipHour(String skipHour) {
        synchronized (skipHours) {
            skipHours.add(skipHour);
        }
    }


    /**
     * Return the items for this channel.
     */
    public Item[] findItems() {
        synchronized (items) {
            Item items[] = new Item[this.items.size()];
            return ((Item[]) this.items.toArray(items));
        }
    }


    /**
     * Return the items for this channel.
     */
    public Item[] getItems() {
        return findItems();
    }


    /**
     * Return the skip days for this channel.
     */
    public String[] findSkipDays() {
        synchronized (skipDays) {
            String skipDays[] = new String[this.skipDays.size()];
            return ((String[]) this.skipDays.toArray(skipDays));
        }
    }


    /**
     * Return the skip hours for this channel.
     */
    public String[] getSkipHours() {
        return findSkipHours();
    }


    /**
     * Return the skip hours for this channel.
     */
    public String[] findSkipHours() {
        synchronized (skipHours) {
            String skipHours[] = new String[this.skipHours.size()];
            return ((String[]) this.skipHours.toArray(skipHours));
        }
    }


    /**
     * Return the skip days for this channel.
     */
    public String[] getSkipDays() {
        return findSkipDays();
    }


    /**
     * Remove an item for this channel.
     *
     * @param item The item to be removed
     */
    public void removeItem(Item item) {
        synchronized (items) {
            items.remove(item);
        }
    }


    /**
     * Remove a skip day for this channel.
     *
     * @param skipDay The skip day to be removed
     */
    public void removeSkipDay(String skipDay) {
        synchronized (skipDays) {
            skipDays.remove(skipDay);
        }
    }


    /**
     * Remove a skip hour for this channel.
     *
     * @param skipHour The skip hour to be removed
     */
    public void removeSkipHour(String skipHour) {
        synchronized (skipHours) {
            skipHours.remove(skipHour);
        }
    }


    /**
     * Render this channel as XML conforming to the RSS 0.91 specification,
     * to the specified output stream, with no indication of character
     * encoding.
     *
     * @param stream The output stream to write to
     */
    public void render(OutputStream stream) {

        try {
            render(stream, null);
        } catch (UnsupportedEncodingException e) {
            ; // Can not happen
        }

    }


    /**
     * Render this channel as XML conforming to the RSS 0.91 specification,
     * to the specified output stream, with the specified character encoding.
     *
     * @param stream The output stream to write to
     * @param encoding The character encoding to declare, or <code>null</code>
     *  for no declaration
     *
     * @exception UnsupportedEncodingException if the named encoding
     *  is not supported
     */
    public void render(OutputStream stream, String encoding)
            throws UnsupportedEncodingException {

        PrintWriter pw = null;
        if (encoding == null) {
            pw = new PrintWriter(stream);
        } else {
            pw = new PrintWriter(new OutputStreamWriter(stream, encoding));
        }
        render(pw, encoding);
        pw.flush();

    }


    /**
     * Render this channel as XML conforming to the RSS 0.91 specification,
     * to the specified writer, with no indication of character encoding.
     *
     * @param writer The writer to render output to
     */
    public void render(Writer writer) {

        render(writer, null);

    }


    /**
     * Render this channel as XML conforming to the RSS 0.91 specification,
     * to the specified writer, indicating the specified character encoding.
     *
     * @param writer The writer to render output to
     * @param encoding The character encoding to declare, or <code>null</code>
     *  for no declaration
     */
    public void render(Writer writer, String encoding) {

        PrintWriter pw = new PrintWriter(writer);
        render(pw, encoding);
        pw.flush();

    }


    /**
     * Render this channel as XML conforming to the RSS 0.91 specification,
     * to the specified writer, with no indication of character encoding.
     *
     * @param writer The writer to render output to
     */
    public void render(PrintWriter writer) {

        render(writer, null);

    }


    /**
     * Render this channel as XML conforming to the RSS 0.91 specification,
     * to the specified writer, indicating the specified character encoding.
     *
     * @param writer The writer to render output to
     * @param encoding The character encoding to declare, or <code>null</code>
     *  for no declaration
     */
    public void render(PrintWriter writer, String encoding) {

        writer.print("<?xml version=\"1.0\"");
        if (encoding != null) {
            writer.print(" encoding=\"");
            writer.print(encoding);
            writer.print("\"");
        }
        writer.println("?>");
        writer.println();

        writer.println("<!DOCTYPE rss PUBLIC");
        writer.println("  \"-//Netscape Communications//DTD RSS 0.91//EN\"");
        writer.println("  \"http://my.netscape.com/publish/formats/rss-0.91.dtd\">");
        writer.println();

        writer.println("<rss version=\"0.91\">");
        writer.println();

        writer.println("  <channel>");
        writer.println();

        writer.print("    <title>");
        writer.print(title);
        writer.println("</title>");

        writer.print("    <description>");
        writer.print(description);
        writer.println("</description>");

        writer.print("    <link>");
        writer.print(link);
        writer.println("</link>");

        writer.print("    <language>");
        writer.print(language);
        writer.println("</language>");

        if (rating != null) {
            writer.print("    <rating>");
            writer.print(rating);
            writer.println("</rating>");
        }

        if (copyright != null) {
            writer.print("    <copyright>");
            writer.print(copyright);
            writer.print("</copyright>");
        }


        if (pubDate != null) {
            writer.print("    <pubDate>");
            writer.print(pubDate);
            writer.println("</pubDate>");
        }

        if (lastBuildDate != null) {
            writer.print("    <lastBuildDate>");
            writer.print(lastBuildDate);
            writer.println("</lastBuildDate>");
        }

        if (docs != null) {
            writer.print("    <docs>");
            writer.print(docs);
            writer.println("</docs>");
        }

        if (managingEditor != null) {
            writer.print("    <managingEditor>");
            writer.print(managingEditor);
            writer.println("</managingEditor>");
        }

        if (webMaster != null) {
            writer.print("    <webMaster>");
            writer.print(webMaster);
            writer.println("</webMaster>");
        }

        writer.println();

        if (image != null) {
            image.render(writer);
            writer.println();
        }

        if (textInput != null) {
            textInput.render(writer);
            writer.println();
        }

        String skipDays[] = findSkipDays();
        if (skipDays.length > 0) {
            writer.println("    <skipDays>");
            for (int i = 0; i < skipDays.length; i++) {
                writer.print("      <skipDay>");
                writer.print(skipDays[i]);
                writer.println("</skipDay>");
            }
            writer.println("    </skipDays>");
        }

        String skipHours[] = findSkipHours();
        if (skipHours.length > 0) {
            writer.println("    <skipHours>");
            for (int i = 0; i < skipHours.length; i++) {
                writer.print("      <skipHour>");
                writer.print(skipHours[i]);
                writer.println("</skipHour>");
            }
            writer.println("    </skipHours>");
            writer.println();
        }

        Item items[] = findItems();
        for (int i = 0; i < items.length; i++) {
            items[i].render(writer);
            writer.println();
        }

        writer.println("  </channel>");
        writer.println();

        writer.println("</rss>");

    }


}
commons-digester-1.6-src/src/examples/rss/src/java/org/apache/commons/digester/rss/Image.java0100644000076600007660000000712210045005073033146 0ustar  crazybullcrazybull/*
 * Copyright 2001-2004 The Apache Software Foundation.
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *      http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * 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.
 */ 


package org.apache.commons.digester.rss;

import java.io.PrintWriter;
import java.io.Serializable;


/**
 * <p>Implementation object representing an <strong>image</strong> in the
 * <em>Rich Site Summary</em> DTD, version 0.91.  This class may be subclassed
 * to further specialize its behavior.</p>
 */

public class Image implements Serializable {


    // ------------------------------------------------------------- Properties


    /**
     * The image description (1-100 characters).
     */
    protected String description = null;

    public String getDescription() {
        return (this.description);
    }

    public void setDescription(String description) {
        this.description = description;
    }


    /**
     * The image height in pixels (1-400).
     */
    protected int height = 31;

    public int getHeight() {
        return (this.height);
    }

    public void setHeight(int height) {
        this.height = height;
    }


    /**
     * The image link (1-500 characters).
     */
    protected String link = null;

    public String getLink() {
        return (this.link);
    }

    public void setLink(String link) {
        this.link = link;
    }


    /**
     * The image alternate text (1-100 characters).
     */
    protected String title = null;

    public String getTitle() {
        return (this.title);
    }

    public void setTitle(String title) {
        this.title = title;
    }


    /**
     * The image location URL (1-500 characters).
     */
    protected String url = null;

    public String getURL() {
        return (this.url);
    }

    public void setURL(String url) {
        this.url = url;
    }


    /**
     * The image width in pixels (1-400).
     */
    protected int width = 31;

    public int getWidth() {
        return (this.width);
    }

    public void setWidth(int width) {
        this.width = width;
    }


    // -------------------------------------------------------- Package Methods


    /**
     * Render this channel as XML conforming to the RSS 0.91 specification,
     * to the specified writer.
     *
     * @param writer The writer to render output to
     */
    void render(PrintWriter writer) {

        writer.println("    <image>");

        writer.print("      <title>");
        writer.print(title);
        writer.println("</title>");

        writer.print("      <url>");
        writer.print(url);
        writer.println("</url>");

        if (link != null) {
            writer.print("      <link>");
            writer.print(link);
            writer.println("</link>");
        }

        writer.print("      <width>");
        writer.print(width);
        writer.println("</width>");

        writer.print("      <height>");
        writer.print(height);
        writer.println("</height>");

        if (description != null) {
            writer.print("      <description>");
            writer.print(description);
            writer.println("</description>");
        }

        writer.println("    </image>");

    }


}
commons-digester-1.6-src/src/examples/rss/src/java/org/apache/commons/digester/rss/Item.java0100644000076600007660000000504210045005073033021 0ustar  crazybullcrazybull/*
 * Copyright 2001-2004 The Apache Software Foundation.
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *      http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permis