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