1
|
package eu.dnetlib.enabling.tools; // NOPMD
|
2
|
|
3
|
import java.io.IOException;
|
4
|
import java.io.StringReader;
|
5
|
|
6
|
import javax.xml.parsers.DocumentBuilderFactory;
|
7
|
import javax.xml.parsers.ParserConfigurationException;
|
8
|
import javax.xml.xpath.XPathExpressionException;
|
9
|
|
10
|
import org.xml.sax.InputSource;
|
11
|
import org.xml.sax.SAXException;
|
12
|
|
13
|
/**
|
14
|
* Opaque resource initialized from a string.
|
15
|
*
|
16
|
* Currently it extends a DOMOpaqueResource, but in future it should postpone xml parsing as late as possible.
|
17
|
*
|
18
|
* @author marko
|
19
|
*
|
20
|
*/
|
21
|
public class StringOpaqueResource extends DOMOpaqueResource {
|
22
|
|
23
|
/**
|
24
|
* construct an opaque resource from a xml source string.
|
25
|
*
|
26
|
* @param source xml source
|
27
|
* @throws XPathExpressionException happens
|
28
|
* @throws SAXException happens
|
29
|
* @throws IOException happens
|
30
|
* @throws ParserConfigurationException happens
|
31
|
*/
|
32
|
public StringOpaqueResource(final String source) throws XPathExpressionException, SAXException, IOException, ParserConfigurationException {
|
33
|
super(getBuilderFactory().newDocumentBuilder().parse(new InputSource(new StringReader(source))));
|
34
|
|
35
|
}
|
36
|
|
37
|
/**
|
38
|
* get a namespace aware document builder factory.
|
39
|
*
|
40
|
* @return document builder factory.
|
41
|
*/
|
42
|
private static DocumentBuilderFactory getBuilderFactory() {
|
43
|
final DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
|
44
|
factory.setNamespaceAware(true);
|
45
|
return factory;
|
46
|
}
|
47
|
|
48
|
}
|