MCPcopy Create free account
hub / github.com/afkT/DevUtils / xmlTag

Method xmlTag

lib/DevJava/src/main/java/dev/utils/JCLogUtils.java:325–361  ·  view source on GitHub ↗

将 XML 格式化缩进后打印为 DEBUG 日志 内容为空时打印 ERROR 提示;解析失败时打印异常与原始 XML。 @param tag 日志 TAG @param xml XML 字符串

(
            final String tag,
            final String xml
    )

Source from the content-addressed store, hash-verified

323 * @param xml XML 字符串
324 */
325 public static void xmlTag(
326 final String tag,
327 final String xml
328 ) {
329 if (JUDGE_PRINT_LOG) {
330 // 判断传入 XML 格式信息是否为 null
331 if (isEmpty(xml)) {
332 printLog(ERROR, tag, "Empty/Null xml content");
333 return;
334 }
335 try {
336 Source xmlInput = new StreamSource(new StringReader(xml));
337 StreamResult xmlOutput = new StreamResult(new StringWriter());
338 Transformer transformer = TransformerFactory.newInstance().newTransformer();
339 transformer.setOutputProperty(OutputKeys.INDENT, "yes");
340 transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "2");
341 transformer.transform(xmlInput, xmlOutput);
342 // 获取打印消息
343 String message = xmlOutput.getWriter().toString().replaceFirst(">", ">\n");
344 // 打印信息
345 printLog(DEBUG, tag, message);
346 } catch (Exception e) {
347 String errorInfo;
348 Throwable throwable = e.getCause();
349 if (throwable != null) {
350 errorInfo = throwable.toString();
351 } else {
352 try {
353 errorInfo = e.toString();
354 } catch (Exception e1) {
355 errorInfo = e1.toString();
356 }
357 }
358 printLog(ERROR, tag, errorInfo + DevFinal.SYMBOL.NEW_LINE + xml);
359 }
360 }
361 }
362
363 // ==========
364 // = 通知输出 =

Callers 1

xmlMethod · 0.95

Calls 4

isEmptyMethod · 0.95
printLogMethod · 0.95
newInstanceMethod · 0.45
toStringMethod · 0.45

Tested by

no test coverage detected