|
6 | 6 | import java.util.logging.Logger; |
7 | 7 | import java.util.regex.Matcher; |
8 | 8 | import java.util.regex.Pattern; |
| 9 | +import org.xmlpull.v1.XmlPullParser; |
| 10 | +import org.xmlpull.v1.XmlPullParserException; |
9 | 11 |
|
10 | 12 | public final class Util { |
11 | 13 |
|
@@ -95,4 +97,44 @@ public static int compareVersions(String version1, String version2) { |
95 | 97 | // Just do silly alphabetical comparison |
96 | 98 | return version1.compareTo(version2); |
97 | 99 | } |
| 100 | + |
| 101 | + public static void logEvent(final XmlPullParser xpp) { |
| 102 | + if (LOGGER.isLoggable(Level.FINEST)) { |
| 103 | + if ("message".equals(xpp.getName())) { // message is handled specially |
| 104 | + return; |
| 105 | + } |
| 106 | + StringBuilder toXml = new StringBuilder(); |
| 107 | + toXml.append("<"); |
| 108 | + try { |
| 109 | + if (xpp.getEventType() == XmlPullParser.END_TAG) { |
| 110 | + toXml.append('/'); |
| 111 | + } |
| 112 | + } catch (XmlPullParserException ex) { |
| 113 | + LOGGER.log(Level.SEVERE, ex.getLocalizedMessage(), ex); |
| 114 | + } |
| 115 | + toXml.append(xpp.getName()); |
| 116 | + for (int i = 0; i < xpp.getAttributeCount(); i++) { |
| 117 | + toXml.append(' '). |
| 118 | + append(xpp.getAttributeName(i)). |
| 119 | + append("='"). |
| 120 | + append(xpp.getAttributeValue(i)). |
| 121 | + append("'"); |
| 122 | + } |
| 123 | + toXml.append('>'); |
| 124 | + LOGGER.finest("Received: " + toXml.toString()); |
| 125 | + } |
| 126 | + } |
| 127 | + |
| 128 | + public static void logMessage(final String message, final boolean debug) { |
| 129 | + if (LOGGER.isLoggable(Level.FINEST)) { |
| 130 | + StringBuilder messageXml = new StringBuilder("<message"); |
| 131 | + if (debug) { |
| 132 | + messageXml.append(" debug='true'"); |
| 133 | + } |
| 134 | + messageXml.append('>'); |
| 135 | + messageXml.append(message); |
| 136 | + messageXml.append("</message>"); |
| 137 | + LOGGER.finest("Received: " + messageXml.toString()); |
| 138 | + } |
| 139 | + } |
98 | 140 | } |
0 commit comments