use of javax.xml.bind.Unmarshaller in project openhab1-addons by openhab.
the class SmarthomaticBinding method activate.
/**
* activate binding
*
*/
@Override
public void activate() {
// log activate of binding
if (baseStation != null) {
logger.info("Smarthomatic Binding activated. BaseStation= {}", baseStation.toString());
}
Bundle bundle = SmarthomaticActivator.getContext().getBundle();
URL fileURL = bundle.getEntry("packet_layout.xml");
Packet packet = null;
try {
InputStream inputStream = fileURL.openConnection().getInputStream();
JAXBContext jaxbContext = JAXBContext.newInstance(Packet.class);
Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller();
packet = (Packet) jaxbUnmarshaller.unmarshal(inputStream);
} catch (IOException e1) {
e1.printStackTrace();
} catch (JAXBException e) {
e.printStackTrace();
}
this.packet = packet;
}
use of javax.xml.bind.Unmarshaller 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.Unmarshaller 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.Unmarshaller 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.Unmarshaller in project openhab1-addons by openhab.
the class CommonIdHandler method loadMapping.
/**
* Load predefined common id mappings from an XML file.
*/
public void loadMapping() throws Exception {
Unmarshaller um = JAXBContext.newInstance(CommonIdList.class).createUnmarshaller();
InputStream stream = Thread.currentThread().getContextClassLoader().getResourceAsStream("weather/common-id-mappings.xml");
CommonIdList mappings = (CommonIdList) um.unmarshal(stream);
for (CommonId commonId : mappings.getCommonIds()) {
for (CommonIdProvider commonIdProvider : commonId.getProviders()) {
Map<String, CommonId> commonIds = providerCommonIds.get(commonIdProvider.getName());
if (commonIds == null) {
commonIds = new HashMap<String, CommonId>();
providerCommonIds.put(commonIdProvider.getName(), commonIds);
}
addCommonId(commonIdProvider.getIds(), "id", commonIdProvider, commonIds, commonId);
addCommonId(commonIdProvider.getIcons(), "icon", commonIdProvider, commonIds, commonId);
}
}
}
Aggregations