Search in sources :

Example 1 with LogEntryXML

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()));
}
Also used : InputSource(org.xml.sax.InputSource) StringReader(java.io.StringReader) IOException(java.io.IOException) Document(org.w3c.dom.Document) LogParseException(com.cosylab.logging.engine.ACS.LogParseException) LogEntryXML(com.cosylab.logging.engine.log.LogEntryXML) LogParseException(com.cosylab.logging.engine.ACS.LogParseException) IOException(java.io.IOException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) SAXException(org.xml.sax.SAXException) ILogEntry(com.cosylab.logging.engine.log.ILogEntry) LogEntry(com.cosylab.logging.engine.log.LogEntry) SAXException(org.xml.sax.SAXException)

Example 2 with LogEntryXML

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);
    }
}
Also used : InputSource(org.xml.sax.InputSource) DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) DocumentBuilder(javax.xml.parsers.DocumentBuilder) LogEntryXML(com.cosylab.logging.engine.log.LogEntryXML)

Aggregations

LogEntryXML (com.cosylab.logging.engine.log.LogEntryXML)2 InputSource (org.xml.sax.InputSource)2 LogParseException (com.cosylab.logging.engine.ACS.LogParseException)1 ILogEntry (com.cosylab.logging.engine.log.ILogEntry)1 LogEntry (com.cosylab.logging.engine.log.LogEntry)1 IOException (java.io.IOException)1 StringReader (java.io.StringReader)1 DocumentBuilder (javax.xml.parsers.DocumentBuilder)1 DocumentBuilderFactory (javax.xml.parsers.DocumentBuilderFactory)1 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)1 Document (org.w3c.dom.Document)1 SAXException (org.xml.sax.SAXException)1