ExternalGrammarDocument implements GrammarDocument { @Override public String getDocument() { if ((document == null) && (buffer != null)) { if (charset == null) { document = new String(buffer); } else { try { document = new String(buffer, charset); } catch (UnsupportedEncodingException ex) { LOGGER.warn("unable to use charset '" + charset + "' to convert grammar '" + uri + "'' Using default.", ex); document = new String(buffer); } } } return document; } ExternalGrammarDocument(final URI source, final byte[] content,
            final String encoding, final boolean ascii); @Override boolean isCacheable(); @Override void setURI(final URI value); @Override URI getURI(); @Override GrammarType getMediaType(); @Override void setMediaType(final GrammarType grammartype); @Override boolean isAscii(); @Override byte[] getBuffer(); @Override String getDocument(); @Override String getTextContent(); @Override boolean equals(final Object obj); @Override boolean equals(final GrammarDocument other); @Override int hashCode(); @Override ModeType getModeType(); @Override void setModeType(final ModeType modeType); @Override String toString();  }
@Test public void testGetDocument() throws Exception { final SrgsXmlDocument srgsDocument = new SrgsXmlDocument(); final Grammar grammar = srgsDocument.getGrammar(); grammar.setVersion("1.0"); grammar.setType(GrammarType.SRGS_XML); final Rule rule = grammar.appendChild(Rule.class); final OneOf oneof = rule.appendChild(OneOf.class); final Item item1 = oneof.appendChild(Item.class); item1.addText("visa"); final Item item2 = oneof.appendChild(Item.class); item2.addText("mastercard"); final Item item3 = oneof.appendChild(Item.class); item3.addText("american express"); final String encoding = System.getProperty("jvoicexml.xml.encoding", "UTF-8"); final ExternalGrammarDocument document = new ExternalGrammarDocument(null, srgsDocument.toString().getBytes(), encoding, true); document.setModeType(ModeType.VOICE); document.setMediaType(GrammarType.SRGS_XML); Assert.assertEquals(srgsDocument.toString(), document.getDocument()); }