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/02/20 03:32:18 UTC

svn commit: r1072477 - in /commons/sandbox/digester3/trunk/src/examples/document-markup: ./ src/main/java/org/ src/main/java/org/apache/ src/main/java/org/apache/commons/ src/main/java/org/apache/commons/digester3/ src/main/java/org/apache/commons/dige...

Author: simonetripodi
Date: Sun Feb 20 02:32:17 2011
New Revision: 1072477

URL: http://svn.apache.org/viewvc?rev=1072477&view=rev
Log:
integrated also the adapted version of 'document-markup' example

Added:
    commons/sandbox/digester3/trunk/src/examples/document-markup/readme.txt   (with props)
    commons/sandbox/digester3/trunk/src/examples/document-markup/src/main/java/org/
    commons/sandbox/digester3/trunk/src/examples/document-markup/src/main/java/org/apache/
    commons/sandbox/digester3/trunk/src/examples/document-markup/src/main/java/org/apache/commons/
    commons/sandbox/digester3/trunk/src/examples/document-markup/src/main/java/org/apache/commons/digester3/
    commons/sandbox/digester3/trunk/src/examples/document-markup/src/main/java/org/apache/commons/digester3/examples/
    commons/sandbox/digester3/trunk/src/examples/document-markup/src/main/java/org/apache/commons/digester3/examples/documentmarkup/
    commons/sandbox/digester3/trunk/src/examples/document-markup/src/main/java/org/apache/commons/digester3/examples/documentmarkup/Main.java   (with props)
    commons/sandbox/digester3/trunk/src/examples/document-markup/src/main/java/org/apache/commons/digester3/examples/documentmarkup/MarkupDigester.java   (with props)
    commons/sandbox/digester3/trunk/src/examples/document-markup/src/main/java/org/apache/commons/digester3/examples/documentmarkup/MarkupModule.java   (with props)
    commons/sandbox/digester3/trunk/src/examples/document-markup/src/main/java/org/apache/commons/digester3/examples/documentmarkup/SetTextSegmentRule.java   (with props)
    commons/sandbox/digester3/trunk/src/examples/document-markup/src/main/java/org/apache/commons/digester3/examples/documentmarkup/TextSegmentHandler.java   (with props)
Modified:
    commons/sandbox/digester3/trunk/src/examples/document-markup/pom.xml

Modified: commons/sandbox/digester3/trunk/src/examples/document-markup/pom.xml
URL: http://svn.apache.org/viewvc/commons/sandbox/digester3/trunk/src/examples/document-markup/pom.xml?rev=1072477&r1=1072476&r2=1072477&view=diff
==============================================================================
--- commons/sandbox/digester3/trunk/src/examples/document-markup/pom.xml (original)
+++ commons/sandbox/digester3/trunk/src/examples/document-markup/pom.xml Sun Feb 20 02:32:17 2011
@@ -32,4 +32,16 @@
     <packaging>jar</packaging>
     <name>Commons Digester :: Examples :: Document Markup</name>
 
+    <build>
+        <plugins>
+            <plugin>
+                <groupId>org.codehaus.mojo</groupId>
+                <artifactId>exec-maven-plugin</artifactId>
+                <configuration>
+                    <mainClass>org.apache.commons.digester3.examples.documentmarkup.Main</mainClass>
+                </configuration>
+            </plugin>
+        </plugins>
+    </build>
+
 </project>

Added: commons/sandbox/digester3/trunk/src/examples/document-markup/readme.txt
URL: http://svn.apache.org/viewvc/commons/sandbox/digester3/trunk/src/examples/document-markup/readme.txt?rev=1072477&view=auto
==============================================================================
--- commons/sandbox/digester3/trunk/src/examples/document-markup/readme.txt (added)
+++ commons/sandbox/digester3/trunk/src/examples/document-markup/readme.txt Sun Feb 20 02:32:17 2011
@@ -0,0 +1,71 @@
+#########################################################################
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You 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:
+  mvn compile
+
+* to build the jar artifact
+  mvn package
+
+* to run:
+  mvn verify
+
+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.

Propchange: commons/sandbox/digester3/trunk/src/examples/document-markup/readme.txt
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: commons/sandbox/digester3/trunk/src/examples/document-markup/readme.txt
------------------------------------------------------------------------------
    svn:keywords = Date Revision Author HeadURL Id

Propchange: commons/sandbox/digester3/trunk/src/examples/document-markup/readme.txt
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: commons/sandbox/digester3/trunk/src/examples/document-markup/src/main/java/org/apache/commons/digester3/examples/documentmarkup/Main.java
URL: http://svn.apache.org/viewvc/commons/sandbox/digester3/trunk/src/examples/document-markup/src/main/java/org/apache/commons/digester3/examples/documentmarkup/Main.java?rev=1072477&view=auto
==============================================================================
--- commons/sandbox/digester3/trunk/src/examples/document-markup/src/main/java/org/apache/commons/digester3/examples/documentmarkup/Main.java (added)
+++ commons/sandbox/digester3/trunk/src/examples/document-markup/src/main/java/org/apache/commons/digester3/examples/documentmarkup/Main.java Sun Feb 20 02:32:17 2011
@@ -0,0 +1,81 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.digester3.examples.documentmarkup;
+
+import static org.apache.commons.digester3.DigesterLoader.newLoader;
+
+import java.io.StringReader;
+
+/** 
+ * 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 {
+
+    /** 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(newLoader(new MarkupModule()).newDigester());
+        d.push(this);
+
+        d.parse(new StringReader("<p>Hi, this is an <i>example</i> of some <b>bold</b> text.</p"));
+
+        System.out.println("Finished.");
+    }
+
+    /** See the run method. */
+    public static void main(String[] args) throws Exception {
+        new Main().run();
+    }
+
+}

Propchange: commons/sandbox/digester3/trunk/src/examples/document-markup/src/main/java/org/apache/commons/digester3/examples/documentmarkup/Main.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: commons/sandbox/digester3/trunk/src/examples/document-markup/src/main/java/org/apache/commons/digester3/examples/documentmarkup/Main.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: commons/sandbox/digester3/trunk/src/examples/document-markup/src/main/java/org/apache/commons/digester3/examples/documentmarkup/Main.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: commons/sandbox/digester3/trunk/src/examples/document-markup/src/main/java/org/apache/commons/digester3/examples/documentmarkup/MarkupDigester.java
URL: http://svn.apache.org/viewvc/commons/sandbox/digester3/trunk/src/examples/document-markup/src/main/java/org/apache/commons/digester3/examples/documentmarkup/MarkupDigester.java?rev=1072477&view=auto
==============================================================================
--- commons/sandbox/digester3/trunk/src/examples/document-markup/src/main/java/org/apache/commons/digester3/examples/documentmarkup/MarkupDigester.java (added)
+++ commons/sandbox/digester3/trunk/src/examples/document-markup/src/main/java/org/apache/commons/digester3/examples/documentmarkup/MarkupDigester.java Sun Feb 20 02:32:17 2011
@@ -0,0 +1,321 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.digester3.examples.documentmarkup;
+
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.Reader;
+import java.net.URL;
+import java.util.List;
+import java.util.Map;
+import java.util.Stack;
+
+import org.apache.commons.digester3.Digester;
+import org.apache.commons.digester3.Rule;
+import org.apache.commons.digester3.spi.Rules;
+import org.apache.commons.digester3.spi.TypeConverter;
+import org.apache.commons.logging.Log;
+import org.xml.sax.Attributes;
+import org.xml.sax.ErrorHandler;
+import org.xml.sax.InputSource;
+import org.xml.sax.Locator;
+import org.xml.sax.SAXException;
+import org.xml.sax.SAXParseException;
+
+/**
+ * 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 implements Digester {
+
+    /**
+     * The text found in the current element since the last child element.
+     */
+    private final  StringBuffer currTextSegment = new StringBuffer();
+
+    private final Digester wrapped;
+
+    public MarkupDigester(Digester wrapped) {
+        this.wrapped = wrapped;
+    }
+
+    public void warning(SAXParseException exception) throws SAXException {
+        this.wrapped.warning(exception);
+    }
+
+    public void error(SAXParseException exception) throws SAXException {
+        this.wrapped.error(exception);
+    }
+
+    public void fatalError(SAXParseException exception) throws SAXException {
+        this.wrapped.fatalError(exception);
+    }
+
+    public void setDocumentLocator(Locator locator) {
+        this.wrapped.setDocumentLocator(locator);
+    }
+
+    public void startDocument() throws SAXException {
+        this.wrapped.startDocument();
+    }
+
+    public void endDocument() throws SAXException {
+        this.wrapped.endDocument();
+    }
+
+    public void startPrefixMapping(String prefix, String uri)
+            throws SAXException {
+        this.wrapped.startPrefixMapping(prefix, uri);
+    }
+
+    public void endPrefixMapping(String prefix) throws SAXException {
+        this.wrapped.endPrefixMapping(prefix);
+    }
+
+    public void startElement(String uri, String localName, String qName,
+            Attributes atts) 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);
+        this.wrapped.startElement(uri, localName, qName, atts);
+    }
+
+    public void endElement(String uri, String localName, String qName)
+            throws SAXException {
+        handleTextSegments();
+        currTextSegment.setLength(0);
+        this.wrapped.endElement(uri, localName, qName);
+    }
+
+    public void characters(char[] ch, int start, int length)
+            throws SAXException {
+        this.wrapped.characters(ch, start, length);
+        this.currTextSegment.append(ch, start, length);
+    }
+
+    public void ignorableWhitespace(char[] ch, int start, int length)
+            throws SAXException {
+        this.wrapped.ignorableWhitespace(ch, start, length);
+    }
+
+    public void processingInstruction(String target, String data)
+            throws SAXException {
+        this.wrapped.processingInstruction(target, data);
+    }
+
+    public void skippedEntity(String name) throws SAXException {
+        this.wrapped.skippedEntity(name);
+    }
+
+    public InputSource resolveEntity(String publicId, String systemId)
+            throws SAXException, IOException {
+        return this.wrapped.resolveEntity(publicId, systemId);
+    }
+
+    public void notationDecl(String name, String publicId, String systemId)
+            throws SAXException {
+        this.wrapped.notationDecl(name, publicId, systemId);
+    }
+
+    public void unparsedEntityDecl(String name, String publicId,
+            String systemId, String notationName) throws SAXException {
+        this.wrapped.unparsedEntityDecl(name, publicId, systemId, notationName);
+    }
+
+    public ClassLoader getClassLoader() {
+        return this.wrapped.getClassLoader();
+    }
+
+    public Log getLog() {
+        return this.wrapped.getLog();
+    }
+
+    public Log getSAXLog() {
+        return this.wrapped.getSAXLog();
+    }
+
+    public String getMatch() {
+        return this.wrapped.getMatch();
+    }
+
+    public Object parse(File file) throws IOException, SAXException {
+        return this.wrapped.parse(file);
+    }
+
+    public Object parse(InputSource input) throws IOException, SAXException {
+        return this.wrapped.parse(input);
+    }
+
+    public Object parse(InputStream input) throws IOException, SAXException {
+        return this.wrapped.parse(input);
+    }
+
+    public Object parse(Reader reader) throws IOException, SAXException {
+        return this.wrapped.parse(reader);
+    }
+
+    public Object parse(String uri) throws IOException, SAXException {
+        return this.wrapped.parse(uri);
+    }
+
+    public Object parse(URL url) throws IOException, SAXException {
+        return this.wrapped.parse(url);
+    }
+
+    public Rules getRules() {
+        return this.wrapped.getRules();
+    }
+
+    public void setRules(Rules rules) {
+        this.wrapped.setRules(rules);
+    }
+
+    public void clear() {
+        this.wrapped.clear();
+    }
+
+    public int getCount() {
+        return this.wrapped.getCount();
+    }
+
+    public void push(Object object) {
+        this.wrapped.push(object);
+    }
+
+    public void push(String stackName, Object value) {
+        this.wrapped.push(stackName, value);
+    }
+
+    public Object pop() {
+        return this.wrapped.pop();
+    }
+
+    public Object pop(String stackName) {
+        return this.wrapped.pop(stackName);
+    }
+
+    public Object peek() {
+        return this.wrapped.peek();
+    }
+
+    public Object peek(String stackName) {
+        return this.wrapped.peek(stackName);
+    }
+
+    public Object peek(int n) {
+        return this.wrapped.peek(n);
+    }
+
+    public Object peek(String stackName, int n) {
+        return this.wrapped.peek(stackName, n);
+    }
+
+    public boolean isEmpty(String stackName) {
+        return this.wrapped.isEmpty(stackName);
+    }
+
+    public Object getRoot() {
+        return this.wrapped.getRoot();
+    }
+
+    public void resetRoot() {
+        this.wrapped.resetRoot();
+    }
+
+    public Object peekParams() {
+        return this.wrapped.peekParams();
+    }
+
+    public Object peekParams(int n) {
+        return this.wrapped.peekParams(n);
+    }
+
+    public void pushParams(Object object) {
+        this.wrapped.pushParams(object);
+    }
+
+    public Object popParams() {
+        return this.wrapped.popParams();
+    }
+
+    public Map<String, String> getCurrentNamespaces() {
+        return this.wrapped.getCurrentNamespaces();
+    }
+
+    public void setErrorHandler(ErrorHandler errorHandler) {
+        this.wrapped.setErrorHandler(errorHandler);
+    }
+
+    public ErrorHandler getErrorHandler() {
+        return this.wrapped.getErrorHandler();
+    }
+
+    public SAXException createSAXException(String message, Exception e) {
+        return this.wrapped.createSAXException(message, e);
+    }
+
+    public SAXException createSAXException(Exception e) {
+        return this.wrapped.createSAXException(e);
+    }
+
+    public SAXException createSAXException(String message) {
+        return this.wrapped.createSAXException(message);
+    }
+
+    public <T> TypeConverter<T> lookupConverter(Class<T> type) {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+    /**
+     * 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<Rule> parentMatches;
+            try {
+                parentMatches = (List<Rule>) ((Stack<Rule>) this.wrapped.getClass().getField("matches").get(this.wrapped)).peek();
+            } catch (Exception e) {
+                throw new SAXException(e);
+            }
+            int len = parentMatches.size();
+            for (Rule r : parentMatches) {
+                if (r instanceof TextSegmentHandler) {
+                    TextSegmentHandler h = (TextSegmentHandler) r;
+                    try {
+                        h.textSegment(segment);
+                    } catch(Exception e) {
+                        throw createSAXException(e);
+                    }
+                }
+            }
+        }
+    }
+
+}

Propchange: commons/sandbox/digester3/trunk/src/examples/document-markup/src/main/java/org/apache/commons/digester3/examples/documentmarkup/MarkupDigester.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: commons/sandbox/digester3/trunk/src/examples/document-markup/src/main/java/org/apache/commons/digester3/examples/documentmarkup/MarkupDigester.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: commons/sandbox/digester3/trunk/src/examples/document-markup/src/main/java/org/apache/commons/digester3/examples/documentmarkup/MarkupDigester.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: commons/sandbox/digester3/trunk/src/examples/document-markup/src/main/java/org/apache/commons/digester3/examples/documentmarkup/MarkupModule.java
URL: http://svn.apache.org/viewvc/commons/sandbox/digester3/trunk/src/examples/document-markup/src/main/java/org/apache/commons/digester3/examples/documentmarkup/MarkupModule.java?rev=1072477&view=auto
==============================================================================
--- commons/sandbox/digester3/trunk/src/examples/document-markup/src/main/java/org/apache/commons/digester3/examples/documentmarkup/MarkupModule.java (added)
+++ commons/sandbox/digester3/trunk/src/examples/document-markup/src/main/java/org/apache/commons/digester3/examples/documentmarkup/MarkupModule.java Sun Feb 20 02:32:17 2011
@@ -0,0 +1,33 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.digester3.examples.documentmarkup;
+
+import org.apache.commons.digester3.AbstractRulesModule;
+
+public final class MarkupModule extends AbstractRulesModule {
+
+    @Override
+    protected void configure() {
+        forPattern("p")
+            .addRule(new SetTextSegmentRule("addSegment"))
+            .then()
+            .callMethod("addAllText").usingElementBodyAsArgument();
+        forPattern("p/i").callMethod("addItalic").usingElementBodyAsArgument();
+        forPattern("p/b").callMethod("addBold").usingElementBodyAsArgument();
+    }
+
+}

Propchange: commons/sandbox/digester3/trunk/src/examples/document-markup/src/main/java/org/apache/commons/digester3/examples/documentmarkup/MarkupModule.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: commons/sandbox/digester3/trunk/src/examples/document-markup/src/main/java/org/apache/commons/digester3/examples/documentmarkup/MarkupModule.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: commons/sandbox/digester3/trunk/src/examples/document-markup/src/main/java/org/apache/commons/digester3/examples/documentmarkup/MarkupModule.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: commons/sandbox/digester3/trunk/src/examples/document-markup/src/main/java/org/apache/commons/digester3/examples/documentmarkup/SetTextSegmentRule.java
URL: http://svn.apache.org/viewvc/commons/sandbox/digester3/trunk/src/examples/document-markup/src/main/java/org/apache/commons/digester3/examples/documentmarkup/SetTextSegmentRule.java?rev=1072477&view=auto
==============================================================================
--- commons/sandbox/digester3/trunk/src/examples/document-markup/src/main/java/org/apache/commons/digester3/examples/documentmarkup/SetTextSegmentRule.java (added)
+++ commons/sandbox/digester3/trunk/src/examples/document-markup/src/main/java/org/apache/commons/digester3/examples/documentmarkup/SetTextSegmentRule.java Sun Feb 20 02:32:17 2011
@@ -0,0 +1,48 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.digester3.examples.documentmarkup;
+
+import org.apache.commons.beanutils.MethodUtils;
+import org.apache.commons.digester3.Rule;
+
+/**
+ * When a text segment is discovered, it calls a specific method on the top
+ * object on the stack.
+ */
+public class SetTextSegmentRule extends Rule implements TextSegmentHandler {
+
+    /**
+     * The method name to call on the parent object.
+     */
+    private String methodName = null;
+
+    public SetTextSegmentRule(String methodName) {
+        this.methodName = methodName;
+    }
+
+    /**
+     * Process the end of this element.
+     */
+    public void textSegment(String text) throws Exception {
+        // Call the specified method
+        MethodUtils.invokeMethod(this.getDigester().peek(0),
+                this.methodName,
+                new Object[]{ text },
+                new Class[]{ String.class });
+    }
+
+}

Propchange: commons/sandbox/digester3/trunk/src/examples/document-markup/src/main/java/org/apache/commons/digester3/examples/documentmarkup/SetTextSegmentRule.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: commons/sandbox/digester3/trunk/src/examples/document-markup/src/main/java/org/apache/commons/digester3/examples/documentmarkup/SetTextSegmentRule.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: commons/sandbox/digester3/trunk/src/examples/document-markup/src/main/java/org/apache/commons/digester3/examples/documentmarkup/SetTextSegmentRule.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: commons/sandbox/digester3/trunk/src/examples/document-markup/src/main/java/org/apache/commons/digester3/examples/documentmarkup/TextSegmentHandler.java
URL: http://svn.apache.org/viewvc/commons/sandbox/digester3/trunk/src/examples/document-markup/src/main/java/org/apache/commons/digester3/examples/documentmarkup/TextSegmentHandler.java?rev=1072477&view=auto
==============================================================================
--- commons/sandbox/digester3/trunk/src/examples/document-markup/src/main/java/org/apache/commons/digester3/examples/documentmarkup/TextSegmentHandler.java (added)
+++ commons/sandbox/digester3/trunk/src/examples/document-markup/src/main/java/org/apache/commons/digester3/examples/documentmarkup/TextSegmentHandler.java Sun Feb 20 02:32:17 2011
@@ -0,0 +1,27 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.digester3.examples.documentmarkup;
+
+/**
+ * Public interface for any Rule subclass which is interested in handling
+ * text segments as well as the complete body text.
+ */
+public interface TextSegmentHandler {
+
+    void textSegment(String text) throws Exception;
+
+}

Propchange: commons/sandbox/digester3/trunk/src/examples/document-markup/src/main/java/org/apache/commons/digester3/examples/documentmarkup/TextSegmentHandler.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: commons/sandbox/digester3/trunk/src/examples/document-markup/src/main/java/org/apache/commons/digester3/examples/documentmarkup/TextSegmentHandler.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: commons/sandbox/digester3/trunk/src/examples/document-markup/src/main/java/org/apache/commons/digester3/examples/documentmarkup/TextSegmentHandler.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain