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