View Javadoc

    1   package net.sourceforge.pmd.util.viewer.model;
    2
    3
    4   import net.sourceforge.pmd.jaxen.Attribute;
    5
    6
    7   /***
    8    * A toolkit for vaious attribute translations
    9    *
    10   * @author Boris Gruschko ( boris at gruschko.org )
    11   * @version $Id: AttributeToolkit.java,v 1.9 2006/10/20 02:40:14 hooperbloob Exp $
    12   */
    13
    14  public class AttributeToolkit {
    15
    16      /***
    17       * formats a value for its usage in XPath expressions
    18       *
    19       * @param attribute atribute which value should be formatted
    20       * @return formmated value
    21       */
    22      public static String formatValueForXPath(Attribute attribute) {
    23          return '\'' + attribute.getValue() + '\'';
    24      }
    25
    26      /***
    27       * constructs a predicate from the given attribute
    28       *
    29       * @param attribute attribute to be formatted as predicate
    30       * @return predicate
    31       */
    32      public static String constructPredicate(Attribute attribute) {
    33          return "[@" + attribute.getName() + '=' +
    34                  formatValueForXPath(attribute) + ']';
    35      }
    36  }