<commit_before>/******************************************************************
*
*	MediaServer for CyberLink
*
*	Copyright (C) <NAME> 2003
*
*	File : MediaServer.java
*
*	10/22/03
*		- first revision.
*	03/30/05
*		- Added a constructor that read the description from memory instead of the file.
*		- Changed it as the default constructor.
*
******************************************************************/

package org.cybergarage.upnp.media.server;

import java.io.*;

import org.cybergarage.net.*;
import org.cybergarage.util.*;
import org.cybergarage.http.*;
import org.cybergarage.upnp.*;
import org.cybergarage.upnp.UPnP;
import org.cybergarage.upnp.device.*;
import org.cybergarage.upnp.media.server.object.*;

public class MediaServer extends Device
{
	////////////////////////////////////////////////
	// Constants
	////////////////////////////////////////////////
	
	public final static String DEVICE_TYPE = "urn:schemas-upnp-org:device:MediaServer:1";
	
	public final static int DEFAULT_HTTP_PORT = 38520;
	
	public final static String DESCRIPTION = 
		"<?xml version=\"1.0\" encoding=\"utf-8\"?>\n" +
		"<root xmlns=\"urn:schemas-upnp-org:device-1-0\">\n" +
		"   <specVersion>\n" +
		"      <major>1</major>\n" +
		"      <minor>0</minor>\n" +
		"   </specVersion>\n" +
		"   <device>\n" +
		"      <deviceType>urn:schemas-upnp-org:device:MediaServer:1</deviceType>\n" +
		"      <friendlyName>Cyber Garage Media Server</friendlyName>\n" +
		"      <manufacturer>Cyber Garage</manufacturer>\n" +
		"      <manufacturerURL>http://www.cybergarage.org</manufacturerURL>\n" +
		"      <modelDescription>Provides content through UPnP ContentDirectory service</modelDescription>\n" +
		"      <modelName>Cyber Garage Media Server</modelName>\n" +
		"      <modelNumber>1.0</modelNumber>\n" +
		"      <modelURL>http://www.cybergarage.org</modelURL>\n" +
		"      <UDN>uuid:362d9414-31a0-48b6-b684-2b4bd38391d0</UDN>\n" +
		"      <serviceList>\n" +
		"         <service>\n" +
		"            <serviceType>urn:schemas-upnp-org:service:ContentDirectory:1</serviceType>\n" +
		"            <serviceId>urn:upnp-org:serviceId:urn:schemas-upnp-org:service:ContentDirectory</serviceId>\n" +
		"            <SCPDURL>/service/ContentDirectory1.xml</SCPDURL>\n" +
		"            <controlURL>/service/ContentDirectory_control</controlURL>\n" +
		"            <eventSubURL>/service/ContentDirectory_event</eventSubURL>\n" +
		"         </service>\n" +
		"         <service>\n" +
		"            <serviceType>urn:schemas-upnp-org:service:ConnectionManager:1</serviceType>\n" +
		"            <serviceId>urn:upnp-org:serviceId:urn:schemas-upnp-org:service:ConnectionManager</serviceId>\n" +
		"            <SCPDURL>/service/ConnectionManager1.xml</SCPDURL>\n" +
		"            <controlURL>/service/ConnectionManager_control</controlURL>\n" +
		"            <eventSubURL>/service/ConnectionManager_event</eventSubURL>\n" +
		"         </service>\n" +
		"      </serviceList>\n" +
		"   </device>\n" +
		"</root>";
	
	////////////////////////////////////////////////
	// Constructor
	////////////////////////////////////////////////
	
	private final static String DESCRIPTION_FILE_NAME = "description/description.xml";
	
	public MediaServer(String descriptionFileName) throws InvalidDescriptionException
	{
		super(new File(descriptionFileName));
		initialize();
	}

	public MediaServer() throws InvalidDescriptionException
	{
		this(DESCRIPTION, ContentDirectory.SCPD, ConnectionManager.SCPD);
	}

	public MediaServer(String description, String contentDirectorySCPD, String connectionManagerSCPD) throws InvalidDescriptionException
	{
		super();
		
		loadDescription(description);
		
		Service servConDir = getService(ContentDirectory.SERVICE_TYPE);
		servConDir.loadSCPD(contentDirectorySCPD);
		
		Service servConMan = getService(ConnectionManager.SERVICE_TYPE);
		servConMan.loadSCPD(connectionManagerSCPD);
		
		initialize();
	}
	
	private void initialize()
	{
		// Netwroking initialization		
		UPnP.setEnable(UPnP.USE_ONLY_IPV4_ADDR);
		String firstIf = HostInterface.getHostAddress(0);
		setInterfaceAddress(firstIf);
		setHTTPPort(DEFAULT_HTTP_PORT);
		
		conDir = new ContentDirectory(this);
		conMan = new ConnectionManager(this);
		
		Service servConDir = getService(ContentDirectory.SERVICE_TYPE);
		servConDir.setActionListener(getContentDirectory());
		servConDir.setQueryListener(getContentDirectory());

		Service servConMan = getService(ConnectionManager.SERVICE_TYPE);
		servConMan.setActionListener(getConnectionManager());
		servConMan.setQueryListener(getConnectionManager());<commit_msg>* Changed the constructor of MediaServer not to throw InvalidDescriptionException.<commit_after>/******************************************************************
*
*	MediaServer for CyberLink
*
*	Copyright (C) <NAME> 2003
*
*	File : MediaServer.java
*
*	10/22/03
*		- first revision.
*	03/30/05
*		- Added a constructor that read the description from memory instead of the file.
*		- Changed it as the default constructor.
*
******************************************************************/

package org.cybergarage.upnp.media.server;

import java.io.*;

import org.cybergarage.net.*;
import org.cybergarage.util.*;
import org.cybergarage.http.*;
import org.cybergarage.upnp.*;
import org.cybergarage.upnp.UPnP;
import org.cybergarage.upnp.device.*;
import org.cybergarage.upnp.media.server.object.*;

public class MediaServer extends Device
{
	////////////////////////////////////////////////
	// Constants
	////////////////////////////////////////////////
	
	public final static String DEVICE_TYPE = "urn:schemas-upnp-org:device:MediaServer:1";
	
	public final static int DEFAULT_HTTP_PORT = 38520;
	
	public final static String DESCRIPTION = 
		"<?xml version=\"1.0\" encoding=\"utf-8\"?>\n" +
		"<root xmlns=\"urn:schemas-upnp-org:device-1-0\">\n" +
		"   <specVersion>\n" +
		"      <major>1</major>\n" +
		"      <minor>0</minor>\n" +
		"   </specVersion>\n" +
		"   <device>\n" +
		"      <deviceType>urn:schemas-upnp-org:device:MediaServer:1</deviceType>\n" +
		"      <friendlyName>Cyber Garage Media Server</friendlyName>\n" +
		"      <manufacturer>Cyber Garage</manufacturer>\n" +
		"      <manufacturerURL>http://www.cybergarage.org</manufacturerURL>\n" +
		"      <modelDescription>Provides content through UPnP ContentDirectory service</modelDescription>\n" +
		"      <modelName>Cyber Garage Media Server</modelName>\n" +
		"      <modelNumber>1.0</modelNumber>\n" +
		"      <modelURL>http://www.cybergarage.org</modelURL>\n" +
		"      <UDN>uuid:362d9414-31a0-48b6-b684-2b4bd38391d0</UDN>\n" +
		"      <serviceList>\n" +
		"         <service>\n" +
		"            <serviceType>urn:schemas-upnp-org:service:ContentDirectory:1</serviceType>\n" +
		"            <serviceId>urn:upnp-org:serviceId:urn:schemas-upnp-org:service:ContentDirectory</serviceId>\n" +
		"            <SCPDURL>/service/ContentDirectory1.xml</SCPDURL>\n" +
		"            <controlURL>/service/ContentDirectory_control</controlURL>\n" +
		"            <eventSubURL>/service/ContentDirectory_event</eventSubURL>\n" +
		"         </service>\n" +
		"         <service>\n" +
		"            <serviceType>urn:schemas-upnp-org:service:ConnectionManager:1</serviceType>\n" +
		"            <serviceId>urn:upnp-org:serviceId:urn:schemas-upnp-org:service:ConnectionManager</serviceId>\n" +
		"            <SCPDURL>/service/ConnectionManager1.xml</SCPDURL>\n" +
		"            <controlURL>/service/ConnectionManager_control</controlURL>\n" +
		"            <eventSubURL>/service/ConnectionManager_event</eventSubURL>\n" +
		"         </service>\n" +
		"      </serviceList>\n" +
		"   </device>\n" +
		"</root>";
	
	////////////////////////////////////////////////
	// Constructor
	////////////////////////////////////////////////
	
	private final static String DESCRIPTION_FILE_NAME = "description/description.xml";
	
	public MediaServer(String descriptionFileName) throws InvalidDescriptionException
	{
		super(new File(descriptionFileName));
		initialize();
	}

	public MediaServer()
	{
		super();
		try {
			initialize(DESCRIPTION, ContentDirectory.SCPD, ConnectionManager.SCPD);
		}
		catch (InvalidDescriptionException ide) {}
	}

	public MediaServer(String description, String contentDirectorySCPD, String connectionManagerSCPD) throws InvalidDescriptionException
	{
		super();
		initialize(description, contentDirectorySCPD, connectionManagerSCPD);
	}
	
	private void initialize(String description, String contentDirectorySCPD, String connectionManagerSCPD) throws InvalidDescriptionException
	{
		loadDescription(description);
		
		Service servConDir = getService(ContentDirectory.SERVICE_TYPE);
		servConDir.loadSCPD(contentDirectorySCPD);
		
		Service servConMan = getService(ConnectionManager.SERVICE_TYPE);
		servConMan.loadSCPD(connectionManagerSCPD);
		
		initialize();
	}
	
	private void initialize()
	{
		// Netwroking initialization		
		UPnP.setEnable(UPnP.USE_ONLY_IPV4_ADDR);
		String firstIf = HostInterface.getHostAddress(0);
		setInterfaceAddress(firstIf);
		setHTTPPort(DEFAULT_HTTP_PORT);
		
		conDir = new ContentDirectory(this);
		conMan = new ConnectionManager(this);
		
		Service servConDir = getService(ContentDirectory.SERVICE_TYPE);
		servConDir.setActionListener(getContentDirectory());
		servConDir.setQueryListener(getContentDirectory());

		Service servConMan = getService(ConnectionManager.SERVICE_TYPE);
		servConMan.setActionListener(getConnectionManager());
		servConMan.setQueryListener(getConnectionManager());
{'fraction_non_alphanumeric': 0.19335220719303764, 'fraction_numerical': 0.013001992240746565, 'mean_word_length': 3.3812586127698667, 'pattern_counts': {'":': 0, '<': 115, '<?xml version=': 2, '>': 115, 'https://': 0, 'lorem ipsum': 0, 'www.': 4, 'xml': 10}, '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': '5633274', 'n_tokens_mistral': 3143, 'n_tokens_neox': 2853, 'n_words': 408}