當前位置: 首頁>>代碼示例>>Java>>正文


Java URL.getRef方法代碼示例

本文整理匯總了Java中java.net.URL.getRef方法的典型用法代碼示例。如果您正苦於以下問題:Java URL.getRef方法的具體用法?Java URL.getRef怎麽用?Java URL.getRef使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在java.net.URL的用法示例。


在下文中一共展示了URL.getRef方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: encodeUrlToHttpFormat

import java.net.URL; //導入方法依賴的package包/類
public static String encodeUrlToHttpFormat(String urlString)
{
    String encodedUrl=null;
    try
    {
        URL url=new URL(urlString);
        URI uri= new URI(url.getProtocol(),url.getUserInfo(),url.getHost(),url.getPort(),url.getPath(),
                url.getQuery(),url.getRef());
        //System.out.println(uri.toURL().toString());
        encodedUrl=uri.toURL().toString();
    }
    catch (Exception exc)
    {
        return null;
    }
    return  encodedUrl;
}
 
開發者ID:gerard-bisama,項目名稱:DHIS2-fhir-lab-app,代碼行數:18,代碼來源:FhirMediatorUtilities.java

示例2: printableURL

import java.net.URL; //導入方法依賴的package包/類
/**
 * <p>Compute the printable representation of a URL, leaving off the
 * scheme/host/port part if no host is specified. This will typically
 * be the case for URLs that were originally created from relative
 * or context-relative URIs.</p>
 *
 * @param url URL to render in a printable representation
 * @return printable representation of a URL
 */
public static String printableURL(URL url) {

    if (url.getHost() != null) {
        return (url.toString());
    }

    String file = url.getFile();
    String ref = url.getRef();
    if (ref == null) {
        return (file);
    } else {
        StringBuffer sb = new StringBuffer(file);
        sb.append('#');
        sb.append(ref);
        return (sb.toString());
    }

}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:28,代碼來源:RequestUtils.java

示例3: getUrlWithQueryString

import java.net.URL; //導入方法依賴的package包/類
/**
 * Will encode url, if not disabled, and adds params on the end of it
 *
 * @param url             String with URL, should be valid URL without params
 * @param params          RequestParams to be appended on the end of URL
 * @param shouldEncodeUrl whether url should be encoded (replaces spaces with %20)
 * @return encoded url if requested with params appended if any available
 */
public static String getUrlWithQueryString(boolean shouldEncodeUrl, String url, RequestParams params) {
    if (url == null)
        return null;

    if (shouldEncodeUrl) {
        try {
            String decodedURL = URLDecoder.decode(url, "UTF-8");
            URL _url = new URL(decodedURL);
            URI _uri = new URI(_url.getProtocol(), _url.getUserInfo(), _url.getHost(), _url.getPort(), _url.getPath(), _url.getQuery(), _url.getRef());
            url = _uri.toASCIIString();
        } catch (Exception ex) {
            // Should not really happen, added just for sake of validity
            log.e(LOG_TAG, "getUrlWithQueryString encoding URL", ex);
        }
    }

    if (params != null) {
        // Construct the query string and trim it, in case it
        // includes any excessive white spaces.
        String paramString = params.getParamString().trim();

        // Only add the query string if it isn't empty and it
        // isn't equal to '?'.
        if (!paramString.equals("") && !paramString.equals("?")) {
            url += url.contains("?") ? "&" : "?";
            url += paramString;
        }
    }

    return url;
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:40,代碼來源:AsyncHttpClient.java

示例4: browse

import java.net.URL; //導入方法依賴的package包/類
/**
 * Browse the given URL
 *
 * @param url url
 * @param name title
 */
public static void browse(final URL url, final String name) {
	if (Desktop.isDesktopSupported()) {
		try {
			// need this strange code, because the URL.toURI() method have
			// some trouble dealing with UTF-8 encoding sometimes
			final URI uri = new URI(url.getProtocol(), url.getAuthority(), url.getPath(), url.getQuery(), url.getRef());
			Desktop.getDesktop().browse(uri);
		} catch (final Exception e) {
			LOGGER.error(e.getMessage(), e);
			JOptionPane.showMessageDialog(null, Resources.getLabel("error.open.url", name));
		}
	} else {
		JOptionPane.showMessageDialog(null, Resources.getLabel("error.open.url", name));
	}
}
 
開發者ID:leolewis,項目名稱:openvisualtraceroute,代碼行數:22,代碼來源:Util.java

示例5: toURI

import java.net.URL; //導入方法依賴的package包/類
public static java.net.URI toURI(URL url) {
    String protocol = url.getProtocol();
    String auth = url.getAuthority();
    String path = url.getPath();
    String query = url.getQuery();
    String ref = url.getRef();
    if (path != null && !(path.startsWith("/")))
        path = "/" + path;

    //
    // In java.net.URI class, a port number of -1 implies the default
    // port number. So get it stripped off before creating URI instance.
    //
    if (auth != null && auth.endsWith(":-1"))
        auth = auth.substring(0, auth.length() - 3);

    java.net.URI uri;
    try {
        uri = createURI(protocol, auth, path, query, ref);
    } catch (java.net.URISyntaxException e) {
        uri = null;
    }
    return uri;
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:25,代碼來源:ParseUtil.java

示例6: parse

import java.net.URL; //導入方法依賴的package包/類
public UrlConditions parse(String urlText) {
    try {
        UrlConditions conditions = new UrlConditions();
        URL url = new URL(urlText);
        if (url.getRef() != null) {
            conditions.setReferenceConditions(equalTo(url.getRef()));
        } else {
            conditions.setReferenceConditions(isEmptyOrNullString());
        }
        conditions.setSchemaConditions(Matchers.equalTo(url.getProtocol()));
        conditions.getHostConditions().add(equalTo(url.getHost()));
        conditions.getPortConditions().add(equalTo(url.getPort()));
        conditions.getPathConditions().add(equalTo(url.getPath()));
        List<NameValuePair> params = UrlParams.parse(url.getQuery(), Charset.forName("UTF-8"));
        for (NameValuePair param : params) {
            conditions.getParameterConditions().put(param.getName(), equalTo(param.getValue()));
        }
        return conditions;
    } catch (MalformedURLException e) {
        throw new IllegalArgumentException(e);
    }

}
 
開發者ID:PawelAdamski,項目名稱:HttpClientMock,代碼行數:24,代碼來源:UrlParser.java

示例7: splitFragmentString

import java.net.URL; //導入方法依賴的package包/類
public static Map<String, String> splitFragmentString(String urlString) {
	try {
		URL url = new URL(urlString);
		Map<String, String> query_pairs = new LinkedHashMap<>();
		String fragmentString = url.getRef();
		if(fragmentString != null) {
			String[] pairs = fragmentString.split("&");
			for (String pair : pairs) {
				int idx = pair.indexOf("=");
				query_pairs.put(URLDecoder.decode(pair.substring(0, idx), "UTF-8"), URLDecoder.decode(pair.substring(idx + 1), "UTF-8"));
			}
		}
		return query_pairs;
	}
	catch (MalformedURLException | UnsupportedEncodingException e) {
		throw new IllegalArgumentException("Could not parse URL: " + urlString, e);
	}
}
 
開發者ID:vaibhav-sinha,項目名稱:kong-java-client,代碼行數:19,代碼來源:UrlUtil.java

示例8: removeInstitution

import java.net.URL; //導入方法依賴的package包/類
@Override
public String removeInstitution(String url)
{
	try
	{
		URL iUrl = getInstitutionUrl();
		URL myUrl = new URL(url);
		String myRef = myUrl.getRef(); // anchor e.g. #post1
		String myUrlNoHost = myUrl.getFile() + (myRef == null ? "" : "#" + myRef);
		return myUrlNoHost.substring(iUrl.getPath().length());
	}
	catch( MalformedURLException ex )
	{
		throw malformedUrl(ex, url);
	}
}
 
開發者ID:equella,項目名稱:Equella,代碼行數:17,代碼來源:InstitutionServiceImpl.java

示例9: toExternalForm

import java.net.URL; //導入方法依賴的package包/類
/**
 * Override as part of the fix for 36534, to ensure toString is correct.
 */
@Override
protected String toExternalForm(URL u) {
	// pre-compute length of StringBuilder
	int len = u.getProtocol().length() + 1;
	if (u.getPath() != null) {
		len += u.getPath().length();
	}
	if (u.getQuery() != null) {
		len += 1 + u.getQuery().length();
	}
	if (u.getRef() != null)
		len += 1 + u.getRef().length();
	StringBuilder result = new StringBuilder(len);
	result.append(u.getProtocol());
	result.append(":");
	if (u.getPath() != null) {
		result.append(u.getPath());
	}
	if (u.getQuery() != null) {
		result.append('?');
		result.append(u.getQuery());
	}
	if (u.getRef() != null) {
		result.append("#");
		result.append(u.getRef());
	}
	return result.toString();
}
 
開發者ID:how2j,項目名稱:lazycat,代碼行數:32,代碼來源:DirContextURLStreamHandler.java

示例10: encodeUrl

import java.net.URL; //導入方法依賴的package包/類
public static String encodeUrl(String url) throws MalformedURLException {
	URL u = new URL(url);
	String path = u.getPath();
	String query = u.getQuery();
	String fragment = u.getRef();
	
	StringBuilder sb = new StringBuilder();
	sb.append(u.getProtocol());
	sb.append("://");
	sb.append(u.getHost());
	
	if (!path.isEmpty()) {
		path = encodePath(path);
		sb.append(path);
	}
	
	if (query != null && !query.isEmpty()) {
		query = encodeQuery(query);
		sb.append("?");
		sb.append(query);
	}
	
	if (fragment != null && !fragment.isEmpty()) {
		fragment = encodeFragment(fragment);
		sb.append("#");
		sb.append(fragment);
	}
	
	return sb.toString();
}
 
開發者ID:code4wt,項目名稱:short-url,代碼行數:31,代碼來源:UrlUtils.java

示例11: createExternalURL

import java.net.URL; //導入方法依賴的package包/類
/** Creates a URL that is suitable for using in a different process on the
 * same node, similarly to URLMapper.EXTERNAL. May just return the original
 * URL if that's good enough.
 * @param url URL that needs to be displayed in browser
 * @param allowJar is <CODE>jar:</CODE> acceptable protocol?
 * @return browsable URL or null
 */
public static URL createExternalURL(URL url, boolean allowJar) {
    if (url == null)
        return null;
    
    URL compliantURL = getFullyRFC2396CompliantURL(url);

    // return if the protocol is fine
    if (isAcceptableProtocol(compliantURL, allowJar))
        return compliantURL;
    
    // remove the anchor
    String anchor = compliantURL.getRef();
    String urlString = compliantURL.toString ();
    int ind = urlString.indexOf('#');
    if (ind >= 0) {
        urlString = urlString.substring(0, ind);
    }
    
    // map to an external URL using the anchor-less URL
    try {
        FileObject fo = URLMapper.findFileObject(new URL(urlString));
        if (fo != null) {
            URL newUrl = getURLOfAppropriateType(fo, allowJar);
            if (newUrl != null) {
                // re-add the anchor if exists
                urlString = newUrl.toString();
                if (ind >=0) {
                    urlString = urlString + "#" + anchor; // NOI18N
                }
                return new URL(urlString);
            }
        }
    }
    catch (MalformedURLException e) {
        Logger.getLogger("global").log(Level.INFO, null, e);
    }
    
    return compliantURL;
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:47,代碼來源:URLUtil.java

示例12: relativizeElement

import java.net.URL; //導入方法依賴的package包/類
protected static void relativizeElement(Element e) {
    // work from leaves to root in each subtree
    final NodeList children = e.getChildNodes();
    for (int i = 0; i < children.getLength(); ++i) {
      final Node n = children.item(i);
      if (n.getNodeType() == Node.ELEMENT_NODE)
        relativizeElement((Element) n);
    }

    // relativize the xlink:href attribute if there is one
    if (e.hasAttributeNS(XLinkSupport.XLINK_NAMESPACE_URI, "href")) {
      try {
        final URL url = new URL(new URL(e.getBaseURI()),
                                XLinkSupport.getXLinkHref(e));
        final String anchor = url.getRef();
        final String name = new File(url.getPath()).getName();
        XLinkSupport.setXLinkHref(e, name + '#' + anchor);
      }
      // FIXME: review error message
      catch (MalformedURLException ex) {
//        ErrorLog.warn(ex);
      }
    }

    // remove xml:base attribute if there is one
    e.removeAttributeNS(XMLSupport.XML_NAMESPACE_URI, "base");
  }
 
開發者ID:ajmath,項目名稱:VASSAL-src,代碼行數:28,代碼來源:SVGImageUtils.java

示例13: toExternalForm

import java.net.URL; //導入方法依賴的package包/類
/**
 * Override as part of the fix for 36534, to ensure toString is correct.
 */
@Override
protected String toExternalForm(URL u) {
    // pre-compute length of StringBuilder
    int len = u.getProtocol().length() + 1;
    if (u.getPath() != null) {
        len += u.getPath().length();
    }
    if (u.getQuery() != null) {
        len += 1 + u.getQuery().length();
    }
    if (u.getRef() != null) 
        len += 1 + u.getRef().length();
    StringBuilder result = new StringBuilder(len);
    result.append(u.getProtocol());
    result.append(":");
    if (u.getPath() != null) {
        result.append(u.getPath());
    }
    if (u.getQuery() != null) {
        result.append('?');
        result.append(u.getQuery());
    }
    if (u.getRef() != null) {
        result.append("#");
        result.append(u.getRef());
    }
    return result.toString();
}
 
開發者ID:liaokailin,項目名稱:tomcat7,代碼行數:32,代碼來源:DirContextURLStreamHandler.java

示例14: toExternalForm

import java.net.URL; //導入方法依賴的package包/類
/**
 * Override as part of the fix for 36534, to ensure toString is correct.
 */
protected String toExternalForm(URL u) {
    // pre-compute length of StringBuffer
    int len = u.getProtocol().length() + 1;
    if (u.getPath() != null) {
        len += u.getPath().length();
    }
    if (u.getQuery() != null) {
        len += 1 + u.getQuery().length();
    }
    if (u.getRef() != null) 
        len += 1 + u.getRef().length();
    StringBuffer result = new StringBuffer(len);
    result.append(u.getProtocol());
    result.append(":");
    if (u.getPath() != null) {
        result.append(u.getPath());
    }
    if (u.getQuery() != null) {
        result.append('?');
        result.append(u.getQuery());
    }
    if (u.getRef() != null) {
        result.append("#");
        result.append(u.getRef());
    }
    return result.toString();
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:31,代碼來源:DirContextURLStreamHandler.java

示例15: getWebResponse

import java.net.URL; //導入方法依賴的package包/類
public static String getWebResponse(String urlString)
{
    try
    {
        URL url = new URL(urlString);
        URI uri = new URI(url.getProtocol(), url.getUserInfo(), url.getHost(), url.getPort(), url.getPath(), url.getQuery(), url.getRef());
        url = uri.toURL();
        // lul
        HttpURLConnection conn = (HttpURLConnection) url.openConnection();
        conn.setRequestMethod("GET");

        if (cookies != null)
        {
            for (String cookie : cookies)
            {
                conn.addRequestProperty("Cookie", cookie.split(";", 2)[0]);
            }
        }
        conn.setRequestProperty("User-Agent", "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/57.0.2987.138 Safari/537.36 Vivaldi/1.8.770.56");
        BufferedReader rd = new BufferedReader(new InputStreamReader(conn.getInputStream()));
        String line;
        StringBuilder respData = new StringBuilder();
        while ((line = rd.readLine()) != null)
        {
            respData.append(line);
        }

        List<String> setCookies = conn.getHeaderFields().get("Set-Cookie");

        if (setCookies != null)
        {
            cookies = setCookies;
        }

        rd.close();
        return respData.toString();
    }
    catch (Throwable t)
    {
        CreeperHost.logger.warn("An error occurred while fetching " + urlString, t);
    }

    return "error";

}
 
開發者ID:CreeperHost,項目名稱:CreeperHostGui,代碼行數:46,代碼來源:Util.java


注:本文中的java.net.URL.getRef方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。