1 /* $Id: Substitutor.java 155412 2005-02-26 12:58:36Z dirkv $ 2 * 3 * Copyright 2003-2004 The Apache Software Foundation. 4 * 5 * Licensed under the Apache License, Version 2.0 (the "License"); 6 * you may not use this file except in compliance with the License. 7 * You may obtain a copy of the License at 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 * See the License for the specific language governing permissions and 15 * limitations under the License. 16 */ 17 18 package org.apache.commons.digester; 19 20 import org.xml.sax.Attributes; 21 22 /** 23 * <p>(Logical) Interface for substitution strategies. 24 * (It happens to be implemented as a Java abstract class to allow 25 * future additions to be made without breaking backwards compatibility.) 26 * </p> 27 * <p> 28 * Usage: When {@link Digester#setSubstitutor} is set, <code>Digester</code> 29 * calls the methods in this interface to create substitute values which will 30 * be passed into the Rule implementations. 31 * Of course, it is perfectly acceptable for implementations not to make 32 * substitutions and simply return the inputs. 33 * </p> 34 * <p>Different strategies are supported for attributes and body text.</p> 35 * 36 * @since 1.6 37 */ 38 public abstract class Substitutor { 39 40 /** 41 * <p>Substitutes the attributes (before they are passed to the 42 * <code>Rule</code> implementations's).</p> 43 * 44 * <p><code>Digester</code> will only call this method a second time 45 * once the original <code>Attributes</code> instance can be safely reused. 46 * The implementation is therefore free to reuse the same <code>Attributes</code> instance 47 * for all calls.</p> 48 * 49 * @param attributes the <code>Attributes</code> passed into <code>Digester</code> by the SAX parser, 50 * not null (but may be empty) 51 * @return <code>Attributes</code> to be passed to the <code>Rule</code> implementations. 52 * This method may pass back the Attributes passed in. 53 * Not null but possibly empty. 54 */ 55 public abstract Attributes substitute(Attributes attributes); 56 57 /** 58 * Substitutes for the body text. 59 * This method may substitute values into the body text of the 60 * elements that Digester parses. 61 * 62 * @param bodyText the body text (as passed to <code>Digester</code>) 63 * @return the body text to be passed to the <code>Rule</code> implementations 64 */ 65 public abstract String substitute(String bodyText); 66 } 67