JVoiceXmlApplication implements Application { public void addDocument(final URI uri, final VoiceXmlDocument doc) throws BadFetchError { if (uri == null) { LOGGER.warn("no URI specified"); return; } if (doc == null) { LOGGER.warn("cannot add a null document to application"); return; } final Vxml vxml = doc.getVxml(); if (vxml == null) { LOGGER.warn("Is this a VoiceXML document? No vxml tag found"); return; } try { baseUri = vxml.getXmlBaseUri(); if (baseUri == null) { baseUri = uri; } final URI currentApplication = vxml.getApplicationUri(); if (currentApplication == null) { loadedDocuments.clear(); root = null; } if (application == null) { application = currentApplication; } else if (!application.equals(currentApplication)) { application = baseUri; loadedDocuments.clear(); root = null; } } catch (URISyntaxException e) { throw new BadFetchError( "Error adding the document to the application", e); } current = doc; final URI resolved = resolve(uri); final URI fragmentLess = removeFragment(resolved); loadedDocuments.put(fragmentLess, current); if (LOGGER.isDebugEnabled()) { LOGGER.debug("loaded documents:"); final Collection<URI> keys = loadedDocuments.keySet(); for (URI loadedUri : keys) { LOGGER.debug("- " + loadedUri); } } } JVoiceXmlApplication();  JVoiceXmlApplication(final ScopeObserver scopeObserver); void addDocument(final URI uri, final VoiceXmlDocument doc); void setRootDocument(final VoiceXmlDocument document); URI getApplication(); URI getXmlBase(); VoiceXmlDocument getCurrentDocument(); URI resolve(final URI uri); URI resolve(final URI base, final URI uri); boolean isLoaded(final URI uri); @Override String toString(); @Override void setLastResult(final List<LastResult> result); @Override List<LastResult> getLastResult();  }
@Test public void testAddDocument() throws JVoiceXMLEvent, Exception { final Application application = new JVoiceXmlApplication(observer); VoiceXmlDocument doc1 = new VoiceXmlDocument(); final Vxml vxml1 = doc1.getVxml(); final URI testUri1 = createUri("scheme", "host", "/path", "fragment"); vxml1.setXmlBase(testUri1); Assert.assertFalse(application.isLoaded(testUri1)); application.addDocument(testUri1, doc1); Assert.assertTrue(application.isLoaded(testUri1)); Assert.assertEquals(testUri1, application.getXmlBase()); VoiceXmlDocument doc2 = new VoiceXmlDocument(); final Vxml vxml2 = doc2.getVxml(); final URI testUri2 = createUri("scheme", "host", "/path", "fragment"); vxml2.setXmlBase(testUri2); application.addDocument(testUri2, doc2); Assert.assertTrue(application.isLoaded(testUri2)); Assert.assertEquals(testUri1, application.getXmlBase()); VoiceXmlDocument doc3 = new VoiceXmlDocument(); final Vxml vxml3 = doc3.getVxml(); final URI testUri3 = createUri("scheme3", "host3", "/path3", "fragment3"); vxml3.setXmlBase(testUri3); application.addDocument(testUri3, doc3); Assert.assertEquals(testUri3, application.getXmlBase()); final URI testUri31 = createUri("scheme3", "host3", "/path3", null); Assert.assertTrue("fragment less document is also loaded", application.isLoaded(testUri31)); }