1. /* $Id: Substitutor.java,v 1.9 2004/05/10 06:52:50 skitching Exp $
  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. package org.apache.commons.digester;
  18. import org.xml.sax.Attributes;
  19. /**
  20. * <p>(Logical) Interface for substitution strategies.
  21. * (It happens to be implemented as a Java abstract class to allow
  22. * future additions to be made without breaking backwards compatibility.)
  23. * </p>
  24. * <p>
  25. * Usage: When {@link Digester#setSubstitutor} is set, <code>Digester</code>
  26. * calls the methods in this interface to create substitute values which will
  27. * be passed into the Rule implementations.
  28. * Of course, it is perfectly acceptable for implementations not to make
  29. * substitutions and simply return the inputs.
  30. * </p>
  31. * <p>Different strategies are supported for attributes and body text.</p>
  32. *
  33. * @since 1.6
  34. */
  35. public abstract class Substitutor {
  36. /**
  37. * <p>Substitutes the attributes (before they are passed to the
  38. * <code>Rule</code> implementations's).</p>
  39. *
  40. * <p><code>Digester</code> will only call this method a second time
  41. * once the original <code>Attributes</code> instance can be safely reused.
  42. * The implementation is therefore free to reuse the same <code>Attributes</code> instance
  43. * for all calls.</p>
  44. *
  45. * @param attributes the <code>Attributes</code> passed into <code>Digester</code> by the SAX parser,
  46. * not null (but may be empty)
  47. * @return <code>Attributes</code> to be passed to the <code>Rule</code> implementations.
  48. * This method may pass back the Attributes passed in.
  49. * Not null but possibly empty.
  50. */
  51. public abstract Attributes substitute(Attributes attributes);
  52. /**
  53. * Substitutes for the body text.
  54. * This method may substitute values into the body text of the
  55. * elements that Digester parses.
  56. *
  57. * @param bodyText the body text (as passed to <code>Digester</code>)
  58. * @return the body text to be passed to the <code>Rule</code> implementations
  59. */
  60. public abstract String substitute(String bodyText);
  61. }