1 /**
2  * Created on Dec 10, 2008
3  *
4  * Copyright (C) Azureus Software, Inc, All Rights Reserved.
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307  USA
19  */
20 
21 package com.aelitis.azureus.util;
22 
23 import com.aelitis.azureus.core.cnetwork.ContentNetwork;
24 import com.aelitis.azureus.core.cnetwork.ContentNetworkManagerFactory;
25 
26 /**
27  * @author TuxPaper
28  * @created Dec 10, 2008
29  *
30  */
31 public class ContentNetworkUtils
32 {
33 
34 	/**
35 	 * Get content network url based on service id.
36 	 * @param cn
37 	 * @param serviceID
38 	 * @return null if service is not supported
39 	 *
40 	 * @since 4.0.0.5
41 	 */
getUrl(ContentNetwork cn, int serviceID)42 	public static String getUrl(ContentNetwork cn, int serviceID) {
43 		try {
44 			if (!cn.isServiceSupported(serviceID)) {
45 				return null;
46 			}
47 			return cn.getServiceURL(serviceID);
48 		} catch (Throwable t) {
49 			return null;
50 		}
51 
52 	}
53 
getContentNetworkFromTarget(String target)54 	public static ContentNetwork getContentNetworkFromTarget(String target) {
55 		ContentNetwork cn = null;
56 		if (target != null && target.startsWith("ContentNetwork.")) {
57 			long networkID = Long.parseLong(target.substring(15));
58 			cn = ContentNetworkManagerFactory.getSingleton().getContentNetwork(
59 					networkID);
60 		}
61 
62 		if (cn == null) {
63 			cn = ConstantsVuze.getDefaultContentNetwork();
64 		}
65 		return cn;
66 	}
67 
getTarget(ContentNetwork cn)68 	public static String getTarget(ContentNetwork cn) {
69 		return "ContentNetwork."
70 				+ (cn == null ? ConstantsVuze.getDefaultContentNetwork().getID()
71 						: cn.getID());
72 	}
73 }
74