1 package com.atlassian.plugin.validation;
2
3 import com.google.common.io.InputSupplier;
4 import org.dom4j.Document;
5 import org.dom4j.DocumentException;
6 import org.dom4j.io.SAXReader;
7
8 import java.io.IOException;
9 import java.io.InputStream;
10 import java.io.Reader;
11
12
13
14
15 abstract class Dom4jUtils {
16 private Dom4jUtils() {
17 }
18
19 public static Document readDocument(final InputStream input) {
20 try {
21 return getSaxReader().read(input);
22 } catch (DocumentException e) {
23 throw new RuntimeException(e);
24 }
25 }
26
27
28
29
30 @Deprecated
31 public static Document readDocument(InputSupplier<? extends Reader> input) {
32 try (Reader reader = input.getInput()) {
33 return readDocument(reader);
34 } catch (DocumentException e) {
35 throw new RuntimeException(e);
36 } catch (IOException e) {
37 throw new RuntimeException(e);
38 }
39 }
40
41 private static Document readDocument(Reader reader) throws DocumentException {
42 return getSaxReader().read(reader);
43 }
44
45 private static SAXReader getSaxReader() {
46 final SAXReader reader = new SAXReader();
47 reader.setMergeAdjacentText(true);
48 return reader;
49 }
50 }