2
* Created on Dec 10, 2008
4
* Copyright 2008 Vuze, Inc. All rights reserved.
5
* This program is free software; you can redistribute it and/or modify
6
* it under the terms of the GNU General Public License as published by
7
* the Free Software Foundation; version 2 of the License only.
9
* This program is distributed in the hope that it will be useful,
10
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
* GNU General Public License for more details.
14
* You should have received a copy of the GNU General Public License
15
* along with this program; if not, write to the Free Software
16
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19
package com.aelitis.azureus.util;
21
import java.net.MalformedURLException;
24
import com.aelitis.azureus.core.cnetwork.ContentNetwork;
25
import com.aelitis.azureus.core.cnetwork.ContentNetworkManagerFactory;
29
* @created Dec 10, 2008
32
public class ContentNetworkUtils
36
* Get content network url based on service id.
39
* @return null if service is not supported
43
public static String getUrl(ContentNetwork cn, int serviceID) {
45
if (!cn.isServiceSupported(serviceID)) {
48
return cn.getServiceURL(serviceID);
49
} catch (Throwable t) {
54
public static String getUrl(ContentNetwork cn, int serviceID, Object[] params) {
56
if (!cn.isServiceSupported(serviceID)) {
59
return cn.getServiceURL(serviceID, params);
60
} catch (Throwable t) {
65
public static ContentNetwork getContentNetworkFromTarget(String target) {
66
ContentNetwork cn = null;
67
if (target != null && target.startsWith("ContentNetwork.")) {
68
long networkID = Long.parseLong(target.substring(15));
69
cn = ContentNetworkManagerFactory.getSingleton().getContentNetwork(
74
cn = ConstantsVuze.getDefaultContentNetwork();
79
public static String getTarget(ContentNetwork cn) {
80
return "ContentNetwork."
81
+ (cn == null ? ConstantsVuze.getDefaultContentNetwork().getID()
85
public static void setSourceRef(String target, String sourceRef,
87
setSourceRef(getContentNetworkFromTarget(target), sourceRef, override);
90
public static void setSourceRef(ContentNetwork cn, String sourceRef,
92
if (cn == ConstantsVuze.getDefaultContentNetwork()) {
95
// always override old source ref if the content network requires
96
// authorization and the user hasn't authorized yet.
97
if (cn.isServiceSupported(ContentNetwork.SERVICE_AUTHORIZE)) {
98
boolean authShown = false;
99
Object oAuthShown = cn.getPersistentProperty(ContentNetwork.PP_AUTH_PAGE_SHOWN);
100
if (oAuthShown instanceof Boolean) {
101
authShown = ((Boolean) oAuthShown).booleanValue();
108
String old = (String) cn.getPersistentProperty(ContentNetwork.PP_SOURCE_REF);
109
if (old == null || override) {
110
if (sourceRef != null && sourceRef.startsWith("http")) {
113
URL url = new URL(sourceRef);
114
sourceRef = url.getHost() + url.getPath();
115
} catch (MalformedURLException e) {
118
cn.setPersistentProperty(ContentNetwork.PP_SOURCE_REF, sourceRef);