Search in sources :

Example 1 with XMLResponseConferenceListParser

use of org.bigbluebutton.freeswitch.voice.freeswitch.response.XMLResponseConferenceListParser in project bigbluebutton by bigbluebutton.

the class GetAllUsersCommand method handleResponse.

public void handleResponse(EslMessage response, ConferenceEventListener eventListener) {
    //Test for Known Conference
    String firstLine = response.getBodyLines().get(0);
    if (!firstLine.startsWith("<?xml")) {
        //            System.out.println("Not XML: [{}]", firstLine);
        return;
    }
    XMLResponseConferenceListParser confXML = new XMLResponseConferenceListParser();
    //get a factory
    SAXParserFactory spf = SAXParserFactory.newInstance();
    try {
        //get a new instance of parser
        SAXParser sp = spf.newSAXParser();
        //Hack turning body lines back into string then to ByteStream.... BLAH!
        String responseBody = StringUtils.join(response.getBodyLines(), "\n");
        //http://mark.koli.ch/2009/02/resolving-orgxmlsaxsaxparseexception-content-is-not-allowed-in-prolog.html
        //This Sux!
        responseBody = responseBody.trim().replaceFirst("^([\\W]+)<", "<");
        ByteArrayInputStream bs = new ByteArrayInputStream(responseBody.getBytes());
        sp.parse(bs, confXML);
        //Maybe move this to XMLResponseConferenceListParser, sendConfrenceEvents ?
        VoiceUserJoinedEvent pj;
        for (ConferenceMember member : confXML.getConferenceList()) {
            //Foreach found member in conference create a JoinedEvent
            String callerId = member.getCallerId();
            String callerIdName = member.getCallerIdName();
            String voiceUserId = callerIdName;
            Matcher matcher = CALLERNAME_PATTERN.matcher(callerIdName);
            if (matcher.matches()) {
                voiceUserId = matcher.group(1).trim();
                callerIdName = matcher.group(2).trim();
            }
            pj = new VoiceUserJoinedEvent(voiceUserId, member.getId().toString(), confXML.getConferenceRoom(), callerId, callerIdName, member.getMuted(), member.getSpeaking(), null);
            eventListener.handleConferenceEvent(pj);
        }
    } catch (SAXException se) {
    //            System.out.println("Cannot parse repsonce. ", se);
    } catch (ParserConfigurationException pce) {
    //            System.out.println("ParserConfigurationException. ", pce);
    } catch (IOException ie) {
    //        	System.out.println("Cannot parse repsonce. IO Exception. ", ie);
    }
}
Also used : XMLResponseConferenceListParser(org.bigbluebutton.freeswitch.voice.freeswitch.response.XMLResponseConferenceListParser) ByteArrayInputStream(java.io.ByteArrayInputStream) Matcher(java.util.regex.Matcher) ConferenceMember(org.bigbluebutton.freeswitch.voice.freeswitch.response.ConferenceMember) SAXParser(javax.xml.parsers.SAXParser) VoiceUserJoinedEvent(org.bigbluebutton.freeswitch.voice.events.VoiceUserJoinedEvent) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) IOException(java.io.IOException) SAXParserFactory(javax.xml.parsers.SAXParserFactory) SAXException(org.xml.sax.SAXException)

Aggregations

ByteArrayInputStream (java.io.ByteArrayInputStream)1 IOException (java.io.IOException)1 Matcher (java.util.regex.Matcher)1 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)1 SAXParser (javax.xml.parsers.SAXParser)1 SAXParserFactory (javax.xml.parsers.SAXParserFactory)1 VoiceUserJoinedEvent (org.bigbluebutton.freeswitch.voice.events.VoiceUserJoinedEvent)1 ConferenceMember (org.bigbluebutton.freeswitch.voice.freeswitch.response.ConferenceMember)1 XMLResponseConferenceListParser (org.bigbluebutton.freeswitch.voice.freeswitch.response.XMLResponseConferenceListParser)1 SAXException (org.xml.sax.SAXException)1