Skip to content

Commit

Permalink
Merge pull request #850 from openpreserve/fix/xml-mod-reporting
Browse files Browse the repository at this point in the history
FIX: Revert XML SAXParseException reporting
  • Loading branch information
carlwilson authored Apr 18, 2023
2 parents 04e6504 + 0290b7e commit 11fb5d9
Show file tree
Hide file tree
Showing 12 changed files with 37 additions and 23 deletions.
6 changes: 6 additions & 0 deletions jhove-bbt/scripts/create-1.28-target.sh
Original file line number Diff line number Diff line change
Expand Up @@ -243,3 +243,9 @@ fi
# Patch release details of the reporting module.
find "${targetRoot}" -type f -name "*.jhove.xml" -exec sed -i 's/jhove\/1.8\/jhove.xsd/jhove\/1.9\/jhove.xsd/' {} \;
find "${targetRoot}" -type f -name "audit.jhove.xml" -exec sed -i 's/outputHandler release="1.9"/outputHandler release="1.10"/' {} \;

# Patch XML reporting tweak differences
find "${targetRoot}" -type f -name "valid-external.dtd.jhove.xml" -exec sed -i 's/The markup in the document preceding the root element must be well-formed. Line = 1/Line = 1/' {} \;
find "${targetRoot}" -type f -name "valid-external.dtd.jhove.xml" -exec sed -i 's/SAXParseException/SAXParseException: The markup in the document preceding the root element must be well-formed./' {} \;
find "${targetRoot}" -type f -name "*parsed-entity.ent.jhove.xml" -exec sed -i 's/Content is not allowed in prolog. Line = 1/Line = 1/' {} \;
find "${targetRoot}" -type f -name "*parsed-entity.ent.jhove.xml" -exec sed -i 's/SAXParseException/SAXParseException: Content is not allowed in prolog./' {} \;
Original file line number Diff line number Diff line change
Expand Up @@ -396,13 +396,7 @@ public int parse(InputStream stream, RepInfo info, int parseIndex) {
if (handler.getSigFlag() && !_parseFromSig) {
info.setSigMatch(_name);
}
info.setMessage(new ErrorMessage(
MessageConstants.XML_HUL_1,
MessageFormat.format(
MessageConstants.XML_HUL_1_SUB.getMessage(),
spe.getMessage(),
spe.getLineNumber(),
spe.getColumnNumber())));
info.setMessage(new ErrorMessage(MessageConstants.INSTANCE.makeSaxParseMessage(spe)));
info.setWellFormed(false);
return 0;
} catch (SAXException se) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
package edu.harvard.hul.ois.jhove.module.xml;

import java.text.MessageFormat;

import org.xml.sax.SAXParseException;

import edu.harvard.hul.ois.jhove.messages.JhoveMessage;
import edu.harvard.hul.ois.jhove.messages.JhoveMessageFactory;
import edu.harvard.hul.ois.jhove.messages.JhoveMessages;
Expand Down Expand Up @@ -63,4 +67,15 @@ public enum MessageConstants {
.getMessage("XML-HUL-12");
public static final JhoveMessage XML_HUL_13 = messageFactory
.getMessage("XML-HUL-13");

public final JhoveMessage makeSaxParseMessage(final SAXParseException spe) {
return JhoveMessages.getMessageInstance(
MessageConstants.XML_HUL_1.getId(),
MessageFormat.format(MessageConstants.XML_HUL_1.getMessage(),
spe.getMessage()),
MessageFormat.format(
MessageConstants.XML_HUL_1_SUB.getMessage(),
spe.getLineNumber(),
spe.getColumnNumber()));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,12 @@
import java.net.URL;
import java.net.URLConnection;
import java.text.MessageFormat;
import java.util.*;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Set;

import org.xml.sax.Attributes;
import org.xml.sax.InputSource;
Expand Down Expand Up @@ -392,9 +397,7 @@ public void unparsedEntityDecl(String name, String publicId,
*/
@Override
public void warning(SAXParseException spe) {
_messages.add(new InfoMessage(
MessageConstants.XML_HUL_1,
spe.getMessage()));
_messages.add(new InfoMessage(MessageConstants.INSTANCE.makeSaxParseMessage(spe)));
}

/**
Expand All @@ -413,14 +416,7 @@ public void error(SAXParseException spe) {
MAXERRORS));
_messages.add(new InfoMessage(message));
} else if (_nErrors < MAXERRORS) {
_messages.add(new ErrorMessage(
MessageConstants.XML_HUL_1,
MessageFormat.format(
MessageConstants.XML_HUL_1_SUB.getMessage(),
spe.getMessage(),
spe.getLineNumber(),
spe.getColumnNumber()
)));
_messages.add(new ErrorMessage(MessageConstants.INSTANCE.makeSaxParseMessage(spe)));
}
++_nErrors;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
XML-HUL-1 = SAXParseException
XML-HUL-1-SUB = {0} Line = {1,number,integer}, Column = {2,number,integer}.
XML-HUL-1 = SAXParseException: {0}
XML-HUL-1-SUB = Line = {0,number,integer}, Column = {1,number,integer}.
XML-HUL-2 = Error messages in excess of {0,number,integer} not reported.
XML-HUL-3 = SAXException: {0}
XML-HUL-4 = Not able to determine end-of-line type.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
XML-HUL-1 = SaxParseException: {0}
XML-HUL-1-SUB = Line = {0,number,integer}, Column = {1,number,integer}.
XML-HUL-2 = Fejlmeddelelser flere end {0} ikke rapporteret
XML-HUL-3 = SaxParseException: {0}
XML-HUL-4 = Ikke i stand til at bestemme typen af linjeslutning
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
XML-HUL-1 = SAXParseException
XML-HUL-1-SUB = {0} Line = {1,number,integer}, Column = {2,number,integer}.
XML-HUL-1 = SAXParseException: {0}
XML-HUL-1-SUB = Line = {0,number,integer}, Column = {1,number,integer}.
XML-HUL-2 = Error messages in excess of {0,number,integer} not reported.
XML-HUL-3 = SAXException: {0}
XML-HUL-4 = Not able to determine end-of-line type.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
XML-HUL-1 = SaxParseException : {0}
XML-HUL-1-SUB = Line = {0,number,integer}, Column = {1,number,integer}.
XML-HUL-2 = {0} messages d'erreur supplémentaires non signalés
XML-HUL-3 = SaxParseException : {0}
XML-HUL-4 = Impossible de déterminer le type de fin de ligne
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
XML-HUL-1 = SaxParseException: {0}
XML-HUL-1-SUB = Line = {0,number,integer}, Column = {1,number,integer}.
XML-HUL-2 = As mensagens de erro acima de {0} não reportadas
XML-HUL-3 = SaxParseException: {0}
XML-HUL-4 = Não foi possível determinar o tipo de fim de linha
Expand Down

0 comments on commit 11fb5d9

Please sign in to comment.