当前位置: 首页>>代码示例>>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;未经允许,请勿转载。