Skip to content

Commit

Permalink
Merge pull request #943 from openpreserve/fix/xml-reporting
Browse files Browse the repository at this point in the history
FIX: Revert XML SAXParseException reporting
  • Loading branch information
carlwilson authored Aug 19, 2024
2 parents 59cdc79 + 37d0802 commit 250f2db
Show file tree
Hide file tree
Showing 12 changed files with 54 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./' {} \;
17 changes: 17 additions & 0 deletions jhove-bbt/scripts/create-1.31-target.sh
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ if [[ -f "${candidateRoot}/examples/modules/TIFF-hul/peppers.tif.jhove.xml" ]];
cp "${candidateRoot}/examples/modules/TIFF-hul/peppers.tif.jhove.xml" "${targetRoot}/examples/modules/TIFF-hul/peppers.tif.jhove.xml"
fi

# Copy the TIFF fix affected files from the candidate to the target
declare -a tiff_affected=("examples/modules/TIFF-hul/cramps.tif.jhove.xml"
"examples/modules/TIFF-hul/text.tif.jhove.xml"
"examples/modules/TIFF-hul/testpage-small.tif.jhove.xml")
Expand All @@ -134,6 +135,7 @@ do
fi
done

# Copy the XHTML fix affected files from the candidate to the target
declare -a xhtml_affected=("errors/modules/HTML-hul/xhtml-trans-no-xml-dec.html.jhove.xml"
"errors/modules/HTML-hul/xhtml-strict-no-xml-dec.html.jhove.xml"
"errors/modules/HTML-hul/xhtml-frames-no-xml-dec.html.jhove.xml"
Expand All @@ -144,3 +146,18 @@ do
cp "${candidateRoot}/${filename}" "${targetRoot}/${filename}"
fi
done

# Copy the XML fix affected files from the candidate to the target
declare -a xhtml_affected=("errors/modules/HTML-hul/xhtml-trans-xml-dec.html.jhove.xml"
"errors/modules/HTML-hul/xhtml-strict-xml-dec.html.jhove.xml"
"errors/modules/HTML-hul/xhtml-frames-xml-dec.html.jhove.xml"
"errors/modules/HTML-hul/xhtml-1-1-xml-dec.html.jhove.xml"
"examples/modules/XML-hul/valid-external.dtd.jhove.xml"
"examples/modules/XML-hul/external-unparsed-entity.ent.jhove.xml"
"examples/modules/XML-hul/external-parsed-entity.ent.jhove.xml")
for filename in "${xhtml_affected[@]}"
do
if [[ -f "${candidateRoot}/${filename}" ]]; then
cp "${candidateRoot}/${filename}" "${targetRoot}/${filename}"
fi
done
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 250f2db

Please sign in to comment.