<commit_before>/*
 * 
 * 
 * Copyright (C) 2005 SIPfoundry Inc.
 * Licensed by SIPfoundry under the LGPL license.
 * 
 * Copyright (C) 2005 Pingtel Corp.
 * Licensed to SIPfoundry under a Contributor Agreement.
 * 
 * $
 */
package org.sipfoundry.sipxconfig.admin.commserver;

import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;

import org.apache.commons.collections.map.LinkedMap;
import org.apache.commons.digester.Digester;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.sipfoundry.sipxconfig.admin.commserver.imdb.ImdbXmlHelper;
import org.sipfoundry.sipxconfig.admin.commserver.imdb.RegistrationItem;
import org.xml.sax.SAXException;

public class RegistrationContextImpl implements RegistrationContext {
    public static final Log LOG = LogFactory.getLog(RegistrationContextImpl.class);

    private static final String REGISTRATION_URL = "https://{0}:{1}/sipdb/registration.xml";

    private String m_server;

    private String m_port;

    /**
     * @see org.sipfoundry.sipxconfig.admin.commserver.RegistrationContext#getRegistrations()
     */
    public List getRegistrations() {
        try {
            URL url = new URL(getUrl());
            InputStream is = url.openStream();
            return getRegistrations(is);
        } catch (FileNotFoundException e) {
            // we are handling this separately - server returns FileNotFound even if everything is
            // OK but we have no registrations present
            LOG.info("No registrations found on the server" + e.getMessage());
            return Collections.EMPTY_LIST;
        } catch (IOException e) {
            LOG.error("Retrieving active registrations failed", e);
            return Collections.EMPTY_LIST;
        } catch (SAXException e) {
            throw new RuntimeException(e);
        }
    }

    List getRegistrations(InputStream is) throws IOException, SAXException {
        Digester digester = ImdbXmlHelper.configureDigester(RegistrationItem.class);
        return (List) digester.parse(is);
    }<commit_msg>XCF-603 Code that cleans duplicate registrations was never called.<commit_after>/*
 * 
 * 
 * Copyright (C) 2005 SIPfoundry Inc.
 * Licensed by SIPfoundry under the LGPL license.
 * 
 * Copyright (C) 2005 Pingtel Corp.
 * Licensed to SIPfoundry under a Contributor Agreement.
 * 
 * $
 */
package org.sipfoundry.sipxconfig.admin.commserver;

import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;

import org.apache.commons.collections.map.LinkedMap;
import org.apache.commons.digester.Digester;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.sipfoundry.sipxconfig.admin.commserver.imdb.ImdbXmlHelper;
import org.sipfoundry.sipxconfig.admin.commserver.imdb.RegistrationItem;
import org.xml.sax.SAXException;

public class RegistrationContextImpl implements RegistrationContext {
    public static final Log LOG = LogFactory.getLog(RegistrationContextImpl.class);

    private static final String REGISTRATION_URL = "https://{0}:{1}/sipdb/registration.xml";

    private String m_server;

    private String m_port;

    /**
     * @see org.sipfoundry.sipxconfig.admin.commserver.RegistrationContext#getRegistrations()
     */
    public List getRegistrations() {
        try {
            URL url = new URL(getUrl());
            InputStream is = url.openStream();
            List registrations = getRegistrations(is);
            return cleanRegistrations(registrations);
        } catch (FileNotFoundException e) {
            // we are handling this separately - server returns FileNotFound even if everything is
            // OK but we have no registrations present
            LOG.info("No registrations found on the server" + e.getMessage());
            return Collections.EMPTY_LIST;
        } catch (IOException e) {
            LOG.error("Retrieving active registrations failed", e);
            return Collections.EMPTY_LIST;
        } catch (SAXException e) {
            throw new RuntimeException(e);
        }
    }

    List getRegistrations(InputStream is) throws IOException, SAXException {
        Digester digester = ImdbXmlHelper.configureDigester(RegistrationItem.class);
        return (List) digester.parse(is);
    }
{'fraction_non_alphanumeric': 0.09264422045893202, 'fraction_numerical': 0.004932446922582029, 'mean_word_length': 3.3466915191053124, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 4}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5568223', 'n_tokens_mistral': 1341, 'n_tokens_neox': 1302, 'n_words': 323}