Project

General

Profile

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.transform.TransformerFactory;
9
import javax.xml.xpath.XPathExpressionException;
10

    
11
import org.xml.sax.InputSource;
12
import org.xml.sax.SAXException;
13

    
14
/**
15
 * Opaque resource initialized from a string.
16
 * 
17
 * Currently it extends a DOMOpaqueResource, but in future it should postpone xml parsing as late as possible.
18
 * 
19
 * @author marko
20
 *
21
 */
22
public class StringOpaqueResource extends DOMOpaqueResource {
23

    
24
	/**
25
	 * construct an opaque resource from a xml source string.
26
	 * 
27
	 * @param source xml source
28
	 * @throws XPathExpressionException happens
29
	 * @throws SAXException happens
30
	 * @throws IOException happens
31
	 * @throws ParserConfigurationException happens
32
	 */
33
	public StringOpaqueResource(final String source, final TransformerFactory transformerFactory) throws XPathExpressionException, SAXException, IOException, ParserConfigurationException {
34
		super(getBuilderFactory().newDocumentBuilder().parse(new InputSource(new StringReader(source))), transformerFactory);
35
		
36
	}
37

    
38
	/**
39
	 * get a namespace aware document builder factory. 
40
	 * 
41
	 * @return document builder factory.
42
	 */
43
	private static DocumentBuilderFactory getBuilderFactory() {
44
		final DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
45
		factory.setNamespaceAware(true);
46
		return factory;
47
	}
48
	
49
}
(16-16/17)