Skip to content

Commit

Permalink
Merge pull request #4408 from dita-ot/feature/sax-parsing-exception-m…
Browse files Browse the repository at this point in the history
…essage

Add message for generic parsing exceptions
  • Loading branch information
jelovirt committed Mar 26, 2024
2 parents e8dfdf4 + 37d8dc3 commit 6872d71
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 2 deletions.
5 changes: 5 additions & 0 deletions src/main/config/messages_template.xml
Original file line number Diff line number Diff line change
Expand Up @@ -450,6 +450,11 @@ See the accompanying LICENSE file for applicable license.
<response>Ignoring chunk operation.</response>
</message>

<message id="DOTJ088E" type="ERROR">
<reason>XML parsing error: %1</reason>
<response></response>
</message>

<!-- End of Java Messages -->

<!-- Start of XSL Messages -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
package org.dita.dost.exception;

import org.dita.dost.log.DITAOTLogger;
import org.dita.dost.log.MessageUtils;
import org.dita.dost.util.Configuration;
import org.xml.sax.ErrorHandler;
import org.xml.sax.SAXException;
Expand Down Expand Up @@ -49,7 +50,10 @@ public void error(final SAXParseException saxException) throws SAXException {
if (mode == Configuration.Mode.STRICT) {
throw ex;
} else {
logger.error(ex.getMessage(), ex);
logger.error(
MessageUtils.getMessage("DOTJ088E", saxException.getMessage()).setLocation(saxException).toString(),
saxException
);
}
}

Expand Down
9 changes: 9 additions & 0 deletions src/main/java/org/dita/dost/log/MessageBean.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import org.w3c.dom.Element;
import org.xml.sax.Attributes;
import org.xml.sax.Locator;
import org.xml.sax.SAXParseException;

/**
* Class description goes here.
Expand Down Expand Up @@ -233,6 +234,14 @@ public MessageBean setLocation(final Location location) {
return ret;
}

public MessageBean setLocation(SAXParseException exception) {
final MessageBean ret = new MessageBean(this);
ret.srcFile = toURI(exception.getSystemId());
ret.srcLine = exception.getLineNumber();
ret.srcColumn = exception.getColumnNumber();
return ret;
}

/**
* Generate string for MessageBean.
* @return string
Expand Down
3 changes: 2 additions & 1 deletion src/test/resources/messages_en_US.properties
Original file line number Diff line number Diff line change
Expand Up @@ -186,4 +186,5 @@ DOTJ082E=Resource {0} is referenced with incorrect path capitalization
DOTJ084E=Included file {0} contained invalid byte sequence for charset {1}
DOTJ021E=File '%1' will not generate output because because all content has been filtered out by DITAVAL "exclude" conditions, or because the file is not valid DITA.
DOTJ086W=Split chunk attribute found on ''<{0}>'' element that does not reference a topic. Ignoring chunk operation.
DOTJ087W=Found chunk attribute with value ''{0}'' inside combine chunk. Ignoring chunk operation.
DOTJ087W=Found chunk attribute with value ''{0}'' inside combine chunk. Ignoring chunk operation.
DOTJ088E=XML parsing error: {0}

0 comments on commit 6872d71

Please sign in to comment.