JsgfGrammarIdentifier implements GrammarIdentifier { @Override public GrammarType identify(final GrammarDocument grammar) { if (grammar == null) { if (LOGGER.isDebugEnabled()) { LOGGER.debug("grammar is null or empty"); } return null; } if (!grammar.isAscii()) { if (LOGGER.isDebugEnabled()) { LOGGER.debug("can only handle ascii grammars"); } return null; } final String document = grammar.getTextContent(); if (document.startsWith(JSGF_HEDAER)) { return GrammarType.JSGF; } final StringTokenizer tok = new StringTokenizer(document, ";"); if (!tok.hasMoreTokens()) { return null; } final String header = tok.nextToken(); if (header.startsWith(JSGF_HEDAER)) { return GrammarType.JSGF; } return null; }  @Override GrammarType identify(final GrammarDocument grammar); @Override GrammarType getSupportedType();  }
@Test public void testIdentify() throws Exception { final GrammarDocument document = GrammarUtil.getGrammarFromResource("/jvoicexml.gram"); final GrammarType type = identifier.identify(document); Assert.assertEquals(GrammarType.JSGF, type); }
@Test public void testIdentifyGrammarNode() throws Exception { final String cr = System.getProperty("line.separator"); final VoiceXmlDocument document = new VoiceXmlDocument(); final Vxml vxml = document.getVxml(); final Form form = vxml.appendChild(Form.class); final Grammar grammar = form.appendChild(Grammar.class); grammar.setType(GrammarType.JSGF); final StringBuilder str = new StringBuilder(); str.append("#JSGF V1.0;"); str.append(cr); str.append("grammar jvoicexml;"); str.append(cr); str.append("public <boolean> = yes{true}|no{false};"); grammar.addCData(str.toString()); final GrammarDocument grammarDocument = new InternalGrammarDocument(grammar); final GrammarType type = identifier.identify(grammarDocument); Assert.assertEquals(GrammarType.JSGF, type); }