-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Remove BOM from UTF-8 encoded file (String) if present
-SITE-3007 ETT GG "Validator broke" - UTF-8-BOM issue
- Loading branch information
Showing
4 changed files
with
39,910 additions
and
560 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 18 additions & 5 deletions
23
src/main/java/org/sitenv/referenceccda/validators/BaseCCDAValidator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,36 @@ | ||
package org.sitenv.referenceccda.validators; | ||
|
||
import java.io.IOException; | ||
import java.io.StringReader; | ||
|
||
import org.apache.log4j.Logger; | ||
import org.xml.sax.InputSource; | ||
import org.xml.sax.SAXException; | ||
import org.xml.sax.XMLReader; | ||
import org.xml.sax.helpers.XMLReaderFactory; | ||
|
||
import java.io.IOException; | ||
import java.io.StringReader; | ||
|
||
public abstract class BaseCCDAValidator { | ||
protected static void trackXPathsInXML(XPathIndexer xpathIndexer, String xmlString) throws SAXException{ | ||
public static final String UTF8_BOM = "\uFEFF"; | ||
private static Logger logger = Logger.getLogger(BaseCCDAValidator.class); | ||
|
||
protected static void trackXPathsInXML(XPathIndexer xpathIndexer, String xmlString) throws SAXException{ | ||
XMLReader parser = XMLReaderFactory.createXMLReader(); | ||
parser.setContentHandler(xpathIndexer); | ||
try { | ||
xmlString = ifHasUtf8BomThenRemove(xmlString); | ||
InputSource inputSource = new InputSource(new StringReader(xmlString)); | ||
parser.parse(inputSource); | ||
} catch (IOException e) { | ||
e.printStackTrace(); | ||
System.out.println("Error In Line Number Routine: Bad filename, path or invalid document."); | ||
logger.error("Error In Line Number Routine: Bad filename, path or invalid document."); | ||
} | ||
} | ||
|
||
private static String ifHasUtf8BomThenRemove(String xml) { | ||
if (xml.startsWith(UTF8_BOM)) { | ||
logger.warn("Found UTF-8 BOM, removing..."); | ||
xml = xml.substring(1); | ||
} | ||
return xml; | ||
} | ||
} |
Oops, something went wrong.