class JsgfGrammarIdentifier implements GrammarIdentifier {

    @Override
    public GrammarType identify(final GrammarDocument grammar) {
        /* make sure grammar is neither null nor empty */
        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;
        }
        /*
         * cut grammar in pieces. Delimiter is ; followed by a
         * newline immediately
         */
        final StringTokenizer tok = new StringTokenizer(document, ";");
        if (!tok.hasMoreTokens()) {
            return null;
        }

        final String header = tok.nextToken();
        if (header.startsWith(JSGF_HEDAER)) {
            return GrammarType.JSGF;
        }
        // TODO Evaluate encoding and version.
        return null;
    }

}