private <T extends Element> Document<T> getDocument(FOMBuilder builder, IRI base, ParserOptions options) throws ParseException { Document<T> document = builder.getFomDocument(); try { if (base != null) document.setBaseUri(base.toString()); if (options != null && options.getCharset() != null) ((OMDocument)document).setCharsetEncoding(options.getCharset()); if (options != null) document.setMustPreserveWhitespace(options.getMustPreserveWhitespace()); } catch (Exception e) { if (!(e instanceof ParseException)) e = new ParseException(e); throw (ParseException)e; } return document; }