use of javax.xml.bind.Marshaller in project orientdb by orientechnologies.
the class OServerConfigurationLoaderXml method load.
public OServerConfiguration load() throws IOException {
try {
if (file != null) {
fileLastModified = file.lastModified();
String path = OFileUtils.getPath(file.getAbsolutePath());
String current = OFileUtils.getPath(new File("").getAbsolutePath());
if (path.startsWith(current))
path = path.substring(current.length() + 1);
OLogManager.instance().info(this, "Loading configuration from: %s...", path);
} else {
OLogManager.instance().info(this, "Loading configuration from input stream");
}
context = JAXBContext.newInstance(rootClass);
Unmarshaller unmarshaller = context.createUnmarshaller();
unmarshaller.setSchema(null);
final OServerConfiguration obj;
if (file != null) {
if (file.exists())
obj = rootClass.cast(unmarshaller.unmarshal(file));
else {
OLogManager.instance().error(this, "Server configuration file not found: %s", file);
return rootClass.getConstructor(OServerConfigurationLoaderXml.class).newInstance(this);
}
obj.location = file.getAbsolutePath();
} else {
obj = rootClass.cast(unmarshaller.unmarshal(inputStream));
obj.location = "memory";
}
// AUTO CONFIGURE SYSTEM CONFIGURATION
OGlobalConfiguration config;
if (obj.properties != null)
for (OServerEntryConfiguration prop : obj.properties) {
try {
config = OGlobalConfiguration.findByKey(prop.name);
if (config != null) {
config.setValue(prop.value);
}
} catch (Exception e) {
}
}
return obj;
} catch (Exception e) {
// SYNTAX ERROR? PRINT AN EXAMPLE
OLogManager.instance().error(this, "Invalid syntax. Below an example of how it should be:", e);
try {
context = JAXBContext.newInstance(rootClass);
Marshaller marshaller = context.createMarshaller();
marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
Object example = rootClass.getConstructor(OServerConfigurationLoaderXml.class).newInstance(this);
marshaller.marshal(example, System.out);
} catch (Exception ex) {
}
throw new IOException(e);
}
}
use of javax.xml.bind.Marshaller 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.Marshaller 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.Marshaller in project OpenAM by OpenRock.
the class XACMLPrivilegeUtils method writeXMLToStream.
public static void writeXMLToStream(PolicySet policySet, OutputStream outputStream) throws EntitlementException {
try {
JAXBContext jaxbContext = JAXBContext.newInstance(XACMLConstants.XACML3_CORE_PKG);
JAXBElement<PolicySet> policySetElement = objectFactory.createPolicySet(policySet);
Marshaller marshaller = jaxbContext.createMarshaller();
marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
marshaller.marshal(policySetElement, outputStream);
} catch (JAXBException je) {
PrivilegeManager.debug.error("JAXBException while mapping privilege to policy:", je);
throw new EntitlementException(EntitlementException.UNABLE_TO_SERIALIZE_OBJECT, je);
}
}
use of javax.xml.bind.Marshaller in project OpenAM by OpenRock.
the class CreateWSFedMetaDataTemplate method createExtendedMetaTemplate.
public static String createExtendedMetaTemplate(String entityId, Map mapParams) throws JAXBException {
JAXBContext jc = WSFederationMetaUtils.getMetaJAXBContext();
com.sun.identity.wsfederation.jaxb.entityconfig.ObjectFactory objFactory = new com.sun.identity.wsfederation.jaxb.entityconfig.ObjectFactory();
FederationConfigElement fedConfig = objFactory.createFederationConfigElement();
fedConfig.setFederationID(entityId);
fedConfig.setHosted(true);
String idpAlias = (String) mapParams.get(MetaTemplateParameters.P_IDP);
if (idpAlias != null) {
buildWSFedIDPConfigTemplate(objFactory, fedConfig, mapParams);
}
String spAlias = (String) mapParams.get(MetaTemplateParameters.P_SP);
if (spAlias != null) {
buildWSFedSPConfigTemplate(objFactory, fedConfig, mapParams);
}
Marshaller m = jc.createMarshaller();
m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
StringWriter pw = new StringWriter();
m.marshal(fedConfig, pw);
return pw.toString();
}
Aggregations