6 package de.uni_hamburg.corpora.utilities;
8 import java.io.ByteArrayInputStream;
9 import java.io.IOException;
10 import java.io.InputStream;
11 import java.io.StringReader;
12 import java.io.StringWriter;
13 import java.io.UnsupportedEncodingException;
14 import java.nio.charset.StandardCharsets;
15 import java.util.logging.Level;
16 import java.util.logging.Logger;
17 import javax.xml.parsers.DocumentBuilder;
18 import javax.xml.parsers.DocumentBuilderFactory;
19 import javax.xml.parsers.ParserConfigurationException;
20 import javax.xml.transform.Transformer;
21 import javax.xml.transform.TransformerException;
22 import javax.xml.transform.TransformerFactory;
23 import javax.xml.transform.dom.DOMSource;
24 import javax.xml.transform.stream.StreamResult;
25 import javax.xml.transform.stream.StreamSource;
26 import org.exmaralda.partitureditor.jexmaralda.BasicTranscription;
27 import org.exmaralda.partitureditor.jexmaralda.JexmaraldaException;
28 import org.jdom.JDOMException;
29 import org.jdom.input.DOMBuilder;
30 import org.jdom.input.SAXBuilder;
31 import org.jdom.output.DOMOutputter;
32 import org.jdom.output.XMLOutputter;
33 import org.xml.sax.InputSource;
34 import org.xml.sax.SAXException;
51 java.util.Scanner s =
new java.util.Scanner(is).useDelimiter(
"\\A");
52 String result = s.hasNext() ? s.next() :
"";
63 InputStream stream =
new ByteArrayInputStream(s.getBytes(StandardCharsets.UTF_8));
86 BasicTranscription btResult = null;
88 BasicTranscription bt =
new BasicTranscription();
89 bt.BasicTranscriptionFromString(btAsString);
91 }
catch (SAXException ex) {
92 Logger.getLogger(
TypeConverter.class.getName()).log(Level.SEVERE, null, ex);
93 }
catch (JexmaraldaException ex) {
94 Logger.getLogger(
TypeConverter.class.getName()).log(Level.SEVERE, null, ex);
106 StreamSource ss =
new StreamSource(
new StringReader(s));
118 return new XMLOutputter().outputString(jdomDocument);
130 org.jdom.Document newDocument = null;
133 InputStream stream = null;
134 SAXBuilder builder =
new SAXBuilder();
135 stream =
new ByteArrayInputStream(stringRespresentingDocument.getBytes(
"UTF-8"));
136 newDocument = builder.build(stream);
137 }
catch (UnsupportedEncodingException ex) {
138 Logger.getLogger(
TypeConverter.class.getName()).log(Level.SEVERE, null, ex);
139 }
catch (JDOMException ex) {
140 Logger.getLogger(
TypeConverter.class.getName()).log(Level.SEVERE, null, ex);
141 }
catch (IOException ex) {
142 Logger.getLogger(
TypeConverter.class.getName()).log(Level.SEVERE, null, ex);
156 org.jdom.Document jdomDoc = null;
158 DOMBuilder builder =
new DOMBuilder();
159 jdomDoc = builder.build(input);
160 }
catch (Exception e) {
161 Logger.getLogger(
TypeConverter.class.getName()).log(Level.SEVERE, null, e);
175 org.w3c.dom.Document w3cDoc = null;
177 DOMOutputter outputter =
new DOMOutputter();
178 w3cDoc = outputter.output(jdomDoc);
179 }
catch (JDOMException je) {
180 Logger.getLogger(
TypeConverter.class.getName()).log(Level.SEVERE, null, je);
192 DOMSource domSource =
new DOMSource(doc);
193 StringWriter writer =
new StringWriter();
194 StreamResult result =
new StreamResult(writer);
195 TransformerFactory tf = TransformerFactory.newInstance();
196 Transformer transformer;
198 transformer = tf.newTransformer();
199 transformer.transform(domSource, result);
200 }
catch (TransformerException ex) {
201 Logger.getLogger(
TypeConverter.class.getName()).log(Level.SEVERE, null, ex);
203 return writer.toString();
214 org.w3c.dom.Document w3cDoc = null;
215 DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
217 DocumentBuilder builder = factory.newDocumentBuilder();
218 w3cDoc = builder.parse(
new InputSource(
new StringReader(stringRespresentingDocument)));
219 }
catch (UnsupportedEncodingException ex) {
220 Logger.getLogger(
TypeConverter.class.getName()).log(Level.SEVERE, null, ex);
221 }
catch (IOException ex) {
222 Logger.getLogger(
TypeConverter.class.getName()).log(Level.SEVERE, null, ex);
223 }
catch (ParserConfigurationException ex) {
224 Logger.getLogger(
TypeConverter.class.getName()).log(Level.SEVERE, null, ex);
225 }
catch (SAXException ex) {
226 Logger.getLogger(
TypeConverter.class.getName()).log(Level.SEVERE, null, ex);
static StreamSource String2StreamSource(String s)
static org.jdom.Document W3cDocument2JdomDocument(org.w3c.dom.Document input)
static org.w3c.dom.Document String2W3cDocument(String stringRespresentingDocument)
static BasicTranscription String2BasicTranscription(String btAsString)
static org.w3c.dom.Document JdomDocument2W3cDocument(org.jdom.Document jdomDoc)
static String InputStream2String(InputStream is)
static String W3cDocument2String(org.w3c.dom.Document doc)
static org.jdom.Document String2JdomDocument(String stringRespresentingDocument)
static InputStream String2InputStream(String s)
static String JdomDocument2String(org.jdom.Document jdomDocument)
static String BasicTranscription2String(BasicTranscription bt)