| Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
| Util |
|
| 3.0;3 |
| 1 | //////////////////////////////////////////////////////////////////////////////// | |
| 2 | // | |
| 3 | // ObjectLab is sponsoring QALab | |
| 4 | // | |
| 5 | // Based in London, we are world leaders in the design and development | |
| 6 | // of bespoke applications for the Securities Financing markets. | |
| 7 | // | |
| 8 | // <a href="http://www.objectlab.co.uk/open">Click here to learn more</a> | |
| 9 | // ___ _ _ _ _ _ | |
| 10 | // / _ \| |__ (_) ___ ___| |_| | __ _| |__ | |
| 11 | // | | | | '_ \| |/ _ \/ __| __| | / _` | '_ \ | |
| 12 | // | |_| | |_) | | __/ (__| |_| |__| (_| | |_) | | |
| 13 | // \___/|_.__// |\___|\___|\__|_____\__,_|_.__/ | |
| 14 | // |__/ | |
| 15 | // | |
| 16 | // http://www.ObjectLab.co.uk | |
| 17 | // --------------------------------------------------------------------------- | |
| 18 | // | |
| 19 | //QALab is released under the GNU General Public License. | |
| 20 | // | |
| 21 | //QALab: Collects QA Statistics from your build over time. | |
| 22 | //2005+, ObjectLab Ltd | |
| 23 | // | |
| 24 | //This library is free software; you can redistribute it and/or | |
| 25 | //modify it under the terms of the GNU General Public | |
| 26 | //License as published by the Free Software Foundation; either | |
| 27 | //version 2.1 of the License, or (at your option) any later version. | |
| 28 | // | |
| 29 | //This library is distributed in the hope that it will be useful, | |
| 30 | //but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 31 | //MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
| 32 | //General Public License for more details. | |
| 33 | // | |
| 34 | //You should have received a copy of the GNU General Public | |
| 35 | //License along with this library; if not, write to the Free Software | |
| 36 | //Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
| 37 | // | |
| 38 | //////////////////////////////////////////////////////////////////////////////// | |
| 39 | package net.objectlab.qalab.util; | |
| 40 | ||
| 41 | import java.util.ArrayList; | |
| 42 | import java.util.Collections; | |
| 43 | import java.util.Iterator; | |
| 44 | import java.util.List; | |
| 45 | import java.util.StringTokenizer; | |
| 46 | ||
| 47 | import org.w3c.dom.NamedNodeMap; | |
| 48 | import org.w3c.dom.Node; | |
| 49 | import org.xml.sax.Attributes; | |
| 50 | ||
| 51 | /** | |
| 52 | * Utility class for list generation and parsing. | |
| 53 | * | |
| 54 | * @author Benoit Xhenseval | |
| 55 | * @version $Revision: 187 $ | |
| 56 | */ | |
| 57 | public final class Util { | |
| 58 | /** | |
| 59 | * default constructor. | |
| 60 | */ | |
| 61 | 0 | private Util() { |
| 62 | 0 | } |
| 63 | ||
| 64 | /** | |
| 65 | * helper method to convert a 'delimiter' separated string to a list. | |
| 66 | * | |
| 67 | * @param str | |
| 68 | * the 'delimiter' separated string | |
| 69 | * @param delimiter | |
| 70 | * typically a ',' | |
| 71 | * @return a list | |
| 72 | */ | |
| 73 | public static List listify(final String str, final String delimiter) { | |
| 74 | 90 | if (str == null) { |
| 75 | 6 | return Collections.EMPTY_LIST; |
| 76 | } | |
| 77 | ||
| 78 | 84 | final StringTokenizer tok = new StringTokenizer(str, delimiter); |
| 79 | 84 | final List list = new ArrayList(); |
| 80 | ||
| 81 | 273 | while (tok.hasMoreElements()) { |
| 82 | 189 | list.add(tok.nextToken().trim()); |
| 83 | 189 | } |
| 84 | ||
| 85 | 84 | return list; |
| 86 | } | |
| 87 | ||
| 88 | /** | |
| 89 | * convert a list to a comma separated string. | |
| 90 | * | |
| 91 | * @param list | |
| 92 | * list to "print" | |
| 93 | * @return a String comma separated. | |
| 94 | */ | |
| 95 | public static String listToCSVString(final List list) { | |
| 96 | 30 | StringBuffer buf = new StringBuffer(); |
| 97 | ||
| 98 | 30 | if (list != null) { |
| 99 | 27 | boolean first = true; |
| 100 | ||
| 101 | 60 | for (Iterator it = list.iterator(); it.hasNext(); first = false) { |
| 102 | 33 | if (!first) { |
| 103 | 9 | buf.append(","); |
| 104 | } | |
| 105 | ||
| 106 | 33 | buf.append((it.next()).toString()); |
| 107 | } | |
| 108 | } | |
| 109 | ||
| 110 | 30 | return buf.toString(); |
| 111 | } | |
| 112 | ||
| 113 | /** | |
| 114 | * Gets the attribute value. | |
| 115 | * | |
| 116 | * @param attrs | |
| 117 | * SAX XML attributes. | |
| 118 | * @param attrName | |
| 119 | * attribute name | |
| 120 | * @param quiet | |
| 121 | * if true, no logging | |
| 122 | * @param logger | |
| 123 | * the logger to use | |
| 124 | * @return String the attribute value | |
| 125 | */ | |
| 126 | public static String getAttributeValue(final Attributes attrs, // NOPMD | |
| 127 | final String attrName, final boolean quiet, // NOPMD | |
| 128 | final TaskLogger logger) { // NOPMD | |
| 129 | 1434 | if (attrs != null) { |
| 130 | 1434 | final String value = attrs.getValue(attrName); |
| 131 | // if (!quiet) { | |
| 132 | // logger.log("Attribute:" + attrName + " value=" | |
| 133 | // + value); | |
| 134 | // } | |
| 135 | 1434 | return value; |
| 136 | } | |
| 137 | ||
| 138 | 0 | return null; |
| 139 | } | |
| 140 | ||
| 141 | /** | |
| 142 | * Gets the attribute value. | |
| 143 | * | |
| 144 | * @param attrs | |
| 145 | * DOM XML attributes. | |
| 146 | * @param attrName | |
| 147 | * attribute name | |
| 148 | * @param quiet | |
| 149 | * if true, no logging | |
| 150 | * @param logger | |
| 151 | * the logger to use | |
| 152 | * @return String the attribute value | |
| 153 | */ | |
| 154 | public static String getAttributeValue(final NamedNodeMap attrs, // NOPMD | |
| 155 | final String attrName, final boolean quiet, // NOPMD | |
| 156 | final TaskLogger logger) { // NOPMD | |
| 157 | 342 | String value = null; |
| 158 | 342 | if (attrs != null) { |
| 159 | 342 | final Node nodeValue = attrs.getNamedItem(attrName); |
| 160 | 342 | if (nodeValue != null) { |
| 161 | 342 | value = nodeValue.getNodeValue(); |
| 162 | } | |
| 163 | // if (!quiet) { | |
| 164 | // logger.log("Attribute DOM:" + attrName + " value=" + value); | |
| 165 | // } | |
| 166 | } | |
| 167 | ||
| 168 | 342 | return value; |
| 169 | } | |
| 170 | } | |
| 171 | /* | |
| 172 | * ObjectLab is sponsoring QALab | |
| 173 | * | |
| 174 | * Based in London, we are world leaders in the design and development | |
| 175 | * of bespoke applications for the securities financing markets. | |
| 176 | * | |
| 177 | * <a href="http://www.objectlab.co.uk/open">Click here to learn more about us</a> | |
| 178 | * ___ _ _ _ _ _ | |
| 179 | * / _ \| |__ (_) ___ ___| |_| | __ _| |__ | |
| 180 | * | | | | '_ \| |/ _ \/ __| __| | / _` | '_ \ | |
| 181 | * | |_| | |_) | | __/ (__| |_| |__| (_| | |_) | | |
| 182 | * \___/|_.__// |\___|\___|\__|_____\__,_|_.__/ | |
| 183 | * |__/ | |
| 184 | * | |
| 185 | * www.ObjectLab.co.uk | |
| 186 | */ |