Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class ExternalEntityResolver implements EntityResolver {
- private Map<String, InputSource> entities;
- public ExternalEntityResolver() {
- entities = new HashMap<>();
- entities.put("xhtml1-strict.dtd", new InputSource(getClass().getClassLoader().getResourceAsStream("entities/xhtml1-strict.dtd")));
- entities.put("xhtml-lat1.ent", new InputSource(getClass().getClassLoader().getResourceAsStream("entities/xhtml-lat1.ent")));
- entities.put("xhtml-special.ent", new InputSource(getClass().getClassLoader().getResourceAsStream("entities/xhtml-special.ent")));
- entities.put("xhtml-symbol.ent", new InputSource(getClass().getClassLoader().getResourceAsStream("entities/xhtml-symbol.ent")));
- }
- @Override
- public InputSource resolveEntity(String publicId, String systemId) throws SAXException, IOException {
- for (Map.Entry<String, InputSource> entity : entities.entrySet()) {
- if (systemId.contains(entity.getKey())) {
- if (entity.getValue().getByteStream() == null) {
- throw new IOException("Local entity [" + entity.getKey() + "] not found!");
- } else {
- return entity.getValue();
- }
- }
- }
- //use default behaviour
- return null;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement