Grammar extends AbstractSrgsNode implements VoiceXmlNode { public boolean isExternalGrammar() throws IllegalAttributeException { if (getSrc() != null) { if (getSrcexpr() != null) { throw new IllegalAttributeException( "It's not allowed to provide src and srcexp attribute."); } if (hasChildNodes()) { throw new IllegalAttributeException( "It's not allowed to provide src attribute and an inline " + "grammar."); } return true; } else if (getSrcexpr() != null) { if (hasChildNodes()) { throw new IllegalAttributeException( "It's not allowed to provide srcexp attribute and an " + "inline grammar."); } return true; } else if (hasChildNodes()) { return false; } throw new IllegalAttributeException("Exactly one of src, srcexpr," + " or an inline grammar must be specified"); } Grammar();   Grammar(final Node node); private  Grammar(final Node n,
            final XmlNodeFactory<? extends XmlNode> factory); @Override String getTagName(); @Override XmlNode newInstance(final Node n,
            final XmlNodeFactory<? extends XmlNode> factory); String getVersion(); void setVersion(final String version); String getModename(); ModeType getMode(); void setMode(final String mode); void setMode(final ModeType mode); String getRoot(); void setRoot(final String root); void setRoot(final Rule rule); Rule getRootRule(); Collection<Rule> getRules(); Collection<Rule> getPublicRules(); Rule getRule(final String name); String getTagFormat(); void setTagFormat(final String tagFormat); String getXmlLang(); Locale getXmlLangObject(); void setXmlLang(final String xmlLang); void setXmlLang(final Locale locale); String getXmlBase(); void setXmlBase(final String xmlBase); String getSrc(); URL getSrcUrl(); URI getSrcUri(); void setSrc(final String src); void setSrc(final URL url); void setSrc(final URI uri); String getScope(); void setScope(final String scope); String getTypename(); GrammarType getType(); void setType(final String type); void setType(final GrammarType type); String getWeight(); void setWeight(final String weight); String getFetchhint(); void setFetchhint(final String fetchhint); String getFetchtimeout(); long getFetchTimeoutAsMsec(); void setFetchtimeout(final String fetchtimeout); String getMaxage(); long getMaxageAsMsec(); void setMaxage(final String maxage); String getMaxstale(); long getMaxstaleAsMsec(); void setMaxstale(final String maxstale); String getSrcexpr(); void setSrcexpr(final String srcexpr); Text addText(final String text); CDATASection addCData(final String data); @Override Collection<String> getAttributeNames(); boolean isExternalGrammar(); static final String TAG_NAME; static final String DEFAULT_XMLNS; static final String ATTRIBUTE_XMLNS; static final String ATTRIBUTE_VERSION; static final String DEFAULT_VERSION; static final String ATTRIBUTE_XML_LANG; static final String ATTRIBUTE_MODE; static final String ATTRIBUTE_ROOT; static final String ATTRIBUTE_TAG_FORMAT; static final String ATTRIBUTE_XML_BASE; static final String ATTRIBUTE_SRC; static final String ATTRIBUTE_SCOPE; static final String SCOPE_DOCUMENT; static final String SCOPE_DIALOG; static final String ATTRIBUTE_TYPE; static final String ATTRIBUTE_WEIGHT; static final String ATTRIBUTE_FETCHHINT; static final String ATTRIBUTE_FETCHTIMEOUT; static final String ATTRIBUTE_MAXAGE; static final String ATTRIBUTE_MAXSTALE; static final String ATTRIBUTE_SRCEXPR; }
@Test(expected = IllegalAttributeException.class) public void testIsExternalInvalid1() throws Exception { File testFile = new File(SRGS_BASE + "external/invalid1.grxml"); final VoiceXmlDocument document = new VoiceXmlDocument( new InputSource(new FileReader(testFile))); final VoiceXmlNode node = (VoiceXmlNode) document.getFirstChild(); if (node instanceof Grammar) { Grammar gr = (Grammar) node; gr.isExternalGrammar(); } }
@Test(expected = IllegalAttributeException.class) public void testIsExternalInvalid2() throws Exception { File testFile = new File(SRGS_BASE + "external/invalid2.grxml"); final VoiceXmlDocument document = new VoiceXmlDocument( new InputSource(new FileReader(testFile))); final VoiceXmlNode node = (VoiceXmlNode) document.getFirstChild(); if (node instanceof Grammar) { Grammar gr = (Grammar) node; gr.isExternalGrammar(); } }
@Test(expected = IllegalAttributeException.class) public void testIsExternalInvalid3() throws Exception { File testFile = new File(SRGS_BASE + "external/invalid3.grxml"); final VoiceXmlDocument document = new VoiceXmlDocument( new InputSource(new FileReader(testFile))); final VoiceXmlNode node = (VoiceXmlNode) document.getFirstChild(); if (node instanceof Grammar) { Grammar gr = (Grammar) node; gr.isExternalGrammar(); } }
@Test(expected = IllegalAttributeException.class) public void testIsExternalInvalid4() throws Exception { File testFile = new File(SRGS_BASE + "external/invalid4.grxml"); final VoiceXmlDocument document = new VoiceXmlDocument( new InputSource(new FileReader(testFile))); final VoiceXmlNode node = (VoiceXmlNode) document.getFirstChild(); if (node instanceof Grammar) { Grammar gr = (Grammar) node; gr.isExternalGrammar(); } }
@Test public void testIsExternalValid1() throws Exception { File testFile = new File(SRGS_BASE + "external/valid1.grxml"); final VoiceXmlDocument document = new VoiceXmlDocument( new InputSource(new FileReader(testFile))); final VoiceXmlNode node = (VoiceXmlNode) document.getFirstChild(); if (node instanceof Grammar) { Grammar gr = (Grammar) node; Assert.assertEquals(true, gr.isExternalGrammar()); } }
@Test public void testIsExternalvalid3() throws Exception { File testFile = new File(SRGS_BASE + "inline/valid1.grxml"); final VoiceXmlDocument document = new VoiceXmlDocument( new InputSource(new FileReader(testFile))); final VoiceXmlNode node = (VoiceXmlNode) document.getFirstChild(); if (node instanceof Grammar) { Grammar gr = (Grammar) node; Assert.assertEquals(false, gr.isExternalGrammar()); } }