mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-01-05 01:50:56 +07:00
use JDOMUtil.writeElement
GitOrigin-RevId: 0ed37f310d6a015bb000291504912ec3edd87568
This commit is contained in:
committed by
intellij-monorepo-bot
parent
a08c52b166
commit
0452ac820f
@@ -1,4 +1,4 @@
|
||||
// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
||||
// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
||||
package com.intellij.util
|
||||
|
||||
import com.intellij.openapi.application.ex.PathManagerEx
|
||||
@@ -340,6 +340,6 @@ internal class JDOMUtilTest {
|
||||
}
|
||||
|
||||
private fun assertElementText(actual: Element, expected: String) {
|
||||
assertThat(JDOMUtil.createOutputter("").outputString(actual)).isEqualTo(expected)
|
||||
assertThat(JDOMUtil.writeElement(actual)).isEqualTo(expected)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
||||
// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
||||
package com.intellij.tasks.impl;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
@@ -16,12 +16,11 @@ import com.intellij.tasks.LocalTask;
|
||||
import com.intellij.tasks.Task;
|
||||
import com.intellij.tasks.TaskRepository;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import org.jdom.Element;
|
||||
import com.intellij.util.text.Matcher;
|
||||
import org.jetbrains.annotations.Nls;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.net.URLEncoder;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.time.Instant;
|
||||
@@ -165,38 +164,13 @@ public final class TaskUtil {
|
||||
return tasksEqual(Arrays.asList(task1), Arrays.asList(task2));
|
||||
}
|
||||
|
||||
/**
|
||||
* Print pretty-formatted XML to {@code logger}, if its level is DEBUG or below.
|
||||
*/
|
||||
public static void prettyFormatXmlToLog(@NotNull Logger logger, @NotNull Element element) {
|
||||
if (logger.isDebugEnabled()) {
|
||||
// alternatively
|
||||
//new XMLOutputter(Format.getPrettyFormat()).outputString(root)
|
||||
logger.debug("\n" + JDOMUtil.createOutputter("\n").outputString(element));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse and print pretty-formatted XML to {@code logger}, if its level is DEBUG or below.
|
||||
*/
|
||||
public static void prettyFormatXmlToLog(@NotNull Logger logger, @NotNull InputStream xml) {
|
||||
if (logger.isDebugEnabled()) {
|
||||
try {
|
||||
logger.debug("\n" + JDOMUtil.createOutputter("\n").outputString(JDOMUtil.load(xml)));
|
||||
}
|
||||
catch (Exception e) {
|
||||
logger.debug(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse and print pretty-formatted XML to {@code logger}, if its level is DEBUG or below.
|
||||
*/
|
||||
public static void prettyFormatXmlToLog(@NotNull Logger logger, @NotNull String xml) {
|
||||
if (logger.isDebugEnabled()) {
|
||||
try {
|
||||
logger.debug("\n" + JDOMUtil.createOutputter("\n").outputString(JDOMUtil.load(xml)));
|
||||
logger.debug("\n" + JDOMUtil.write(JDOMUtil.load(xml)));
|
||||
}
|
||||
catch (Exception e) {
|
||||
logger.debug(e);
|
||||
@@ -219,21 +193,6 @@ public final class TaskUtil {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse and print pretty-formatted Json to {@code logger}, if its level is DEBUG or below.
|
||||
*/
|
||||
public static void prettyFormatJsonToLog(@NotNull Logger logger, @NotNull JsonElement json) {
|
||||
if (logger.isDebugEnabled()) {
|
||||
try {
|
||||
Gson gson = new GsonBuilder().setPrettyPrinting().create();
|
||||
logger.debug("\n" + gson.toJson(json));
|
||||
}
|
||||
catch (JsonSyntaxException e) {
|
||||
logger.debug("Malformed JSON\n" + json);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Perform standard {@code application/x-www-urlencoded} translation for string {@code s}.
|
||||
*
|
||||
@@ -244,12 +203,12 @@ public final class TaskUtil {
|
||||
}
|
||||
|
||||
public static List<Task> filterTasks(final String pattern, final List<? extends Task> tasks) {
|
||||
final com.intellij.util.text.Matcher matcher = getMatcher(pattern);
|
||||
final Matcher matcher = getMatcher(pattern);
|
||||
return ContainerUtil.mapNotNull(tasks,
|
||||
task -> matcher.matches(task.getPresentableId()) || matcher.matches(task.getSummary()) ? task : null);
|
||||
}
|
||||
|
||||
private static com.intellij.util.text.Matcher getMatcher(String pattern) {
|
||||
private static Matcher getMatcher(String pattern) {
|
||||
StringTokenizer tokenizer = new StringTokenizer(pattern, " ");
|
||||
StringBuilder builder = new StringBuilder();
|
||||
while (tokenizer.hasMoreTokens()) {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
||||
package com.intellij.util;
|
||||
|
||||
import com.intellij.openapi.util.JDOMUtil;
|
||||
@@ -27,7 +27,7 @@ public class XMLOutputterTest extends TestCase {
|
||||
|
||||
private static String printElement(Element root) throws IOException {
|
||||
XMLOutputter xmlOutputter = JDOMUtil.createOutputter("\n");
|
||||
final Format format = xmlOutputter.getFormat().setOmitDeclaration(true).setOmitEncoding(true).setExpandEmptyElements(true);
|
||||
Format format = xmlOutputter.getFormat().setOmitDeclaration(true).setOmitEncoding(true).setExpandEmptyElements(true);
|
||||
xmlOutputter.setFormat(format);
|
||||
|
||||
CharArrayWriter writer = new CharArrayWriter();
|
||||
|
||||
Reference in New Issue
Block a user