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