01: package net.sourceforge.pmd.util.viewer.model;
02:
03: import net.sourceforge.pmd.jaxen.Attribute;
04:
05: /**
06: * A toolkit for vaious attribute translations
07: *
08: * @author Boris Gruschko ( boris at gruschko.org )
09: * @version $Id: AttributeToolkit.java 4710 2006-10-20 02:40:14Z hooperbloob $
10: */
11:
12: public class AttributeToolkit {
13:
14: /**
15: * formats a value for its usage in XPath expressions
16: *
17: * @param attribute atribute which value should be formatted
18: * @return formmated value
19: */
20: public static String formatValueForXPath(Attribute attribute) {
21: return '\'' + attribute.getValue() + '\'';
22: }
23:
24: /**
25: * constructs a predicate from the given attribute
26: *
27: * @param attribute attribute to be formatted as predicate
28: * @return predicate
29: */
30: public static String constructPredicate(Attribute attribute) {
31: return "[@" + attribute.getName() + '='
32: + formatValueForXPath(attribute) + ']';
33: }
34: }
|