001package org.apache.commons.digester3;
002
003/*
004 * Licensed to the Apache Software Foundation (ASF) under one
005 * or more contributor license agreements.  See the NOTICE file
006 * distributed with this work for additional information
007 * regarding copyright ownership.  The ASF licenses this file
008 * to you under the Apache License, Version 2.0 (the
009 * "License"); you may not use this file except in compliance
010 * with the License.  You may obtain a copy of the License at
011 *
012 *   http://www.apache.org/licenses/LICENSE-2.0
013 *
014 * Unless required by applicable law or agreed to in writing,
015 * software distributed under the License is distributed on an
016 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
017 * KIND, either express or implied.  See the License for the
018 * specific language governing permissions and limitations
019 * under the License.
020 */
021
022import org.xml.sax.Attributes;
023
024/**
025 * <p>
026 * (Logical) Interface for substitution strategies. (It happens to be implemented as a Java abstract class to allow
027 * future additions to be made without breaking backwards compatibility.)
028 * </p>
029 * <p>
030 * Usage: When {@link Digester#setSubstitutor} is set, <code>Digester</code> calls the methods in this interface to
031 * create substitute values which will be passed into the Rule implementations. Of course, it is perfectly acceptable
032 * for implementations not to make substitutions and simply return the inputs.
033 * </p>
034 * <p>
035 * Different strategies are supported for attributes and body text.
036 * </p>
037 * 
038 * @since 1.6
039 */
040public abstract class Substitutor
041{
042
043    /**
044     * <p>
045     * Substitutes the attributes (before they are passed to the <code>Rule</code> implementations's).
046     * </p>
047     * <p>
048     * <code>Digester</code> will only call this method a second time once the original <code>Attributes</code> instance
049     * can be safely reused. The implementation is therefore free to reuse the same <code>Attributes</code> instance for
050     * all calls.
051     * </p>
052     * 
053     * @param attributes the <code>Attributes</code> passed into <code>Digester</code> by the SAX parser, not null (but
054     *            may be empty)
055     * @return <code>Attributes</code> to be passed to the <code>Rule</code> implementations. This method may pass back
056     *         the Attributes passed in. Not null but possibly empty.
057     */
058    public abstract Attributes substitute( Attributes attributes );
059
060    /**
061     * Substitutes for the body text. This method may substitute values into the body text of the elements that Digester
062     * parses.
063     * 
064     * @param bodyText the body text (as passed to <code>Digester</code>)
065     * @return the body text to be passed to the <code>Rule</code> implementations
066     */
067    public abstract String substitute( String bodyText );
068
069}