GslGrammarIdentifier 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(GSL_HEDAER)) { return GrammarType.GSL; } return null; }  @Override GrammarType identify(final GrammarDocument grammar); @Override GrammarType getSupportedType();  }
@Test public void testIdentify() throws Exception { final GrammarDocument document = GrammarUtil.getGrammarFromResource("/test.gsl"); final GrammarType type = identifier.identify(document); Assert.assertEquals(GrammarType.GSL, 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.GSL); final StringBuilder str = new StringBuilder(); str.append(";GSL2.0;" + cr); str.append("Digit:public [0 1 2 3 4 5 6 7 8 9]"); grammar.addCData(str.toString()); final GrammarDocument grammarDocument = new InternalGrammarDocument(grammar); final GrammarType type = identifier.identify(grammarDocument); Assert.assertEquals(GrammarType.GSL, type); }