use of com.cosylab.logging.engine.log.LogEntryXML in project ACS by ACS-Community.
the class ACSLogParserDOM method parse.
/* (non-Javadoc)
* @see com.cosylab.logging.engine.ACS.ACSLogParser#parse(java.lang.String)
*/
public synchronized ILogEntry parse(String string) throws LogParseException {
Document document = null;
try {
document = builder.parse(new InputSource(new StringReader(string)));
} catch (IOException ioe) {
// cannot get here
System.err.println("Exception parsing " + ioe.getMessage());
throw new LogParseException(ioe);
} catch (Exception e) {
/* There was an exception parsing the log, but before giving up
* we try to fix markup issues inside the text that is contained in the XML */
document = null;
String newLogString = XmlNormalizer.normalizeXMLEmbeddedTextOnly(string);
try {
document = builder.parse(new InputSource(new StringReader(newLogString)));
System.out.println("Fatal error recovered:");
System.out.println("\tOriginal log entry: " + string);
System.out.println("\tCleaned log entry: " + newLogString + "\n");
} catch (IOException ex1) {
System.err.println("Failed to parse the following log entry:");
System.err.println(string);
System.err.println("with IO exception ");
throw new LogParseException(ex1);
} catch (SAXException ex2) {
System.err.println("Failed to parse the following log entry:");
System.err.println(string);
System.err.println("with parser exception ");
throw new LogParseException(ex2);
}
}
return new LogEntry(new LogEntryXML(document.getFirstChild()));
}
use of com.cosylab.logging.engine.log.LogEntryXML in project ACS by ACS-Community.
the class LogEntryTest method testLogEntry1.
public void testLogEntry1() {
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
try {
for (TestEntry entry : testEntries) {
DocumentBuilder db = factory.newDocumentBuilder();
doc = db.parse(new InputSource(new java.io.StringReader(entry.log)));
Node root = doc.getFirstChild();
LogEntryXML le = new LogEntryXML(root);
String act = le.getEntryTypeAsString();
String exp = entry.logType;
// Checks whether starting and supposedly starting tags match.
assertEquals("The starting tag is different from expected.", exp, act);
}
} catch (Exception e) {
System.out.println("Exception: " + e);
}
}
Aggregations