Advertisement
Guest User

Untitled

a guest
Oct 25th, 2016
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.29 KB | None | 0 0
  1. class ExternalEntityResolver implements EntityResolver {
  2. private Map<String, InputSource> entities;
  3.  
  4. public ExternalEntityResolver() {
  5. entities = new HashMap<>();
  6. entities.put("xhtml1-strict.dtd", new InputSource(getClass().getClassLoader().getResourceAsStream("entities/xhtml1-strict.dtd")));
  7. entities.put("xhtml-lat1.ent", new InputSource(getClass().getClassLoader().getResourceAsStream("entities/xhtml-lat1.ent")));
  8. entities.put("xhtml-special.ent", new InputSource(getClass().getClassLoader().getResourceAsStream("entities/xhtml-special.ent")));
  9. entities.put("xhtml-symbol.ent", new InputSource(getClass().getClassLoader().getResourceAsStream("entities/xhtml-symbol.ent")));
  10. }
  11.  
  12. @Override
  13. public InputSource resolveEntity(String publicId, String systemId) throws SAXException, IOException {
  14. for (Map.Entry<String, InputSource> entity : entities.entrySet()) {
  15. if (systemId.contains(entity.getKey())) {
  16. if (entity.getValue().getByteStream() == null) {
  17. throw new IOException("Local entity [" + entity.getKey() + "] not found!");
  18. } else {
  19. return entity.getValue();
  20. }
  21. }
  22. }
  23. //use default behaviour
  24. return null;
  25. }
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement