use of javax.xml.bind.JAXBContext in project openhab1-addons by openhab.
the class TestSHCMessage method setUp.
/**
* common setup
*
* @throws Exception
*/
@Before
public void setUp() throws Exception {
File file = new File("src/main/resources/packet_layout.xml");
JAXBContext jaxbContext = JAXBContext.newInstance(Packet.class);
Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller();
packet = (Packet) jaxbUnmarshaller.unmarshal(file);
}
use of javax.xml.bind.JAXBContext in project openhab1-addons by openhab.
the class LgTvAppSet method loadapps.
/**
* read applications out of string into a list
*
* @param s
* @throws JAXBException
*/
public void loadapps(String s) throws JAXBException {
JAXBContext jc;
jc = JAXBContext.newInstance(envelope.class);
Unmarshaller unmarshaller = jc.createUnmarshaller();
int start = s.indexOf("<envelope>");
int stop = s.indexOf("</envelope>") + "</envelope>".length();
String t = s.substring(start, stop);
StringReader reader = new StringReader(t);
envel = null;
envel = (envelope) unmarshaller.unmarshal(reader);
}
use of javax.xml.bind.JAXBContext in project openhab1-addons by openhab.
the class LgTvChannelSet method savetofile.
/**
* Save Channel List to File f
*
* @param f
*/
public void savetofile(String f) {
Writer writer = null;
JAXBContext jc;
try {
jc = JAXBContext.newInstance(envelope.class);
Marshaller marshaller = jc.createMarshaller();
marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(f), "utf-8"));
marshaller.marshal(envel, writer);
} catch (PropertyException e) {
logger.error("error in savetofile", e);
} catch (JAXBException e) {
logger.error("error in savetofile", e);
} catch (IOException ex) {
logger.error("error in savetofile", ex);
} finally {
try {
writer.close();
} catch (Exception ex) {
}
}
}
use of javax.xml.bind.JAXBContext in project openhab1-addons by openhab.
the class LgTvEventChannelChanged method readevent.
public String readevent(String s) throws JAXBException {
JAXBContext jc;
jc = JAXBContext.newInstance(envelope.class);
Unmarshaller unmarshaller = jc.createUnmarshaller();
int start = s.indexOf("<envelope>");
int stop = s.indexOf("</envelope>") + "</envelope>".length();
String t = s.substring(start, stop);
// System.out.println(t);
StringReader reader = new StringReader(t);
envel = null;
envel = (envelope) unmarshaller.unmarshal(reader);
Marshaller marshaller = jc.createMarshaller();
marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
StringWriter sw = new StringWriter();
marshaller.marshal(envel, sw);
return new String(sw.toString());
}
use of javax.xml.bind.JAXBContext in project openhab1-addons by openhab.
the class DenonConnector method getDocument.
private <T> T getDocument(String uri, Class<T> response) {
try {
String result = doHttpRequest("GET", uri, null);
logger.trace("result of getDocument for uri '{}':\r\n{}", uri, result);
if (StringUtils.isNotBlank(result)) {
JAXBContext jc = JAXBContext.newInstance(response);
XMLInputFactory xif = XMLInputFactory.newInstance();
XMLStreamReader xsr = xif.createXMLStreamReader(IOUtils.toInputStream(result));
xsr = new PropertyRenamerDelegate(xsr);
@SuppressWarnings("unchecked") T obj = (T) jc.createUnmarshaller().unmarshal(xsr);
return obj;
}
} catch (UnmarshalException e) {
logger.debug("Failed to unmarshal xml document: {}", e.getMessage());
} catch (JAXBException e) {
logger.debug("Unexpected error occurred during unmarshalling of document: {}", e.getMessage());
} catch (XMLStreamException e) {
logger.debug("Communication error: {}", e.getMessage());
}
return null;
}
Aggregations