use of javax.xml.stream.XMLOutputFactory in project OpenAttestation by OpenAttestation.
the class TAHelper method getHostAttestationReport.
// hostName == internetAddress.toString() or Hostname.toString() or IPAddress.toString()
// vmmName == tblHosts.getVmmMleId().getName()
public String getHostAttestationReport(String hostName, HashMap<String, PcrManifest> pcrManifestMap, String vmmName) throws Exception {
XMLOutputFactory xof = XMLOutputFactory.newInstance();
XMLStreamWriter xtw;
StringWriter sw = new StringWriter();
/*
// We need to check if the host supports TPM or not. Only way we can do it
// using the host table contents is by looking at the AIK Certificate. Based
// on this flag we generate the attestation report.
boolean tpmSupport = true;
String hostType = "";
if (tblHosts.getAIKCertificate() == null || tblHosts.getAIKCertificate().isEmpty()) {
tpmSupport = false;
}
* */
// XXX assuming it supports TPM since it's trust agent and we got a pcr manifest (which we only get from getQuoteInformationFromHost if the tpm quote was verified, which means we saved the AIK certificate when we did that)
boolean tpmSupport = true;
// xtw = xof.createXMLStreamWriter(new FileWriter("c:\\temp\\nb_xml.xml"));
xtw = xof.createXMLStreamWriter(sw);
xtw.writeStartDocument();
xtw.writeStartElement("Host_Attestation_Report");
xtw.writeAttribute("Host_Name", hostName);
xtw.writeAttribute("Host_VMM", vmmName);
xtw.writeAttribute("TXT_Support", String.valueOf(tpmSupport));
if (tpmSupport == true) {
ArrayList<IManifest> pcrMFList = new ArrayList<IManifest>();
pcrMFList.addAll(pcrManifestMap.values());
for (IManifest pcrInfo : pcrMFList) {
PcrManifest pInfo = (PcrManifest) pcrInfo;
xtw.writeStartElement("PCRInfo");
xtw.writeAttribute("ComponentName", String.valueOf(pInfo.getPcrNumber()));
xtw.writeAttribute("DigestValue", pInfo.getPcrValue().toUpperCase());
xtw.writeEndElement();
}
} else {
xtw.writeStartElement("PCRInfo");
xtw.writeAttribute("Error", "Host does not support TPM.");
xtw.writeEndElement();
}
xtw.writeEndElement();
xtw.writeEndDocument();
xtw.flush();
xtw.close();
String attestationReport = sw.toString();
return attestationReport;
}
use of javax.xml.stream.XMLOutputFactory in project uPortal by Jasig.
the class XmlUtilitiesImpl method serializeXMLEvents.
@Override
public String serializeXMLEvents(List<XMLEvent> xmlEvents, boolean isHtml) {
final XMLOutputFactory outputFactory;
if (isHtml) {
outputFactory = this.getHtmlOutputFactory();
} else {
outputFactory = this.getXmlOutputFactory();
}
final StringWriter writer = new StringWriter();
final XMLEventWriter xmlEventWriter;
try {
xmlEventWriter = new IndentingXMLEventWriter(outputFactory.createXMLEventWriter(writer));
} catch (XMLStreamException e) {
throw new RuntimeException("Failed to create XMLEventWriter", e);
}
try {
for (final XMLEvent bufferedEvent : xmlEvents) {
xmlEventWriter.add(bufferedEvent);
}
xmlEventWriter.flush();
xmlEventWriter.close();
} catch (XMLStreamException e) {
throw new RuntimeException("Failed to write XMLEvents to XMLEventWriter", e);
}
return writer.toString();
}
use of javax.xml.stream.XMLOutputFactory in project uPortal by Jasig.
the class XSLTComponentTest method serializeXMLEventReader.
protected String serializeXMLEventReader(XMLEventReader reader) {
final StringWriter writer = new StringWriter();
final XMLOutputFactory outputFactory = XMLOutputFactory.newInstance();
outputFactory.setProperty("javax.xml.stream.isRepairingNamespaces", true);
final XMLEventWriter xmlEventWriter;
try {
xmlEventWriter = outputFactory.createXMLEventWriter(writer);
} catch (XMLStreamException e) {
throw new RuntimeException("Failed to create XMLEventWriter", e);
}
try {
xmlEventWriter.setDefaultNamespace("http://www.w3.org/1999/xhtml");
xmlEventWriter.add(reader);
xmlEventWriter.flush();
xmlEventWriter.close();
} catch (XMLStreamException e) {
throw new RuntimeException("Failed to write events to Writer", e);
}
return writer.toString();
}
use of javax.xml.stream.XMLOutputFactory in project webservices-axiom by apache.
the class TestSetPrefixScope method runTest.
protected void runTest() throws Throwable {
XMLOutputFactory factory = staxImpl.newNormalizedXMLOutputFactory();
XMLStreamWriter writer = factory.createXMLStreamWriter(new ByteArrayOutputStream());
writer.writeStartDocument();
writer.writeStartElement("root");
writer.setPrefix("p", "urn:ns");
writer.writeStartElement("child");
assertEquals("p", writer.getPrefix("urn:ns"));
writer.writeEndElement();
assertEquals("p", writer.getPrefix("urn:ns"));
writer.writeEndElement();
writer.writeEndDocument();
writer.close();
}
use of javax.xml.stream.XMLOutputFactory in project webservices-axiom by apache.
the class TestCreateXMLEventWriterWithNullEncoding method runTest.
protected void runTest() throws Throwable {
XMLOutputFactory factory = staxImpl.newNormalizedXMLOutputFactory();
// This should cause an exception
try {
factory.createXMLEventWriter(System.out, null);
} catch (Throwable ex) {
// Expected
return;
}
// Attention here: since the fail method works by throwing an exception and we
// catch Throwable, it must be invoked outside of the catch block!
fail("Expected createXMLEventWriter to throw an exception");
}
Aggregations