.net ref java_Java URL.getRef方法代碼示例

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

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

示例1: encodeUrlToHttpFormat

​點讚 3

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,

示例2: printableURL

​點讚 3

import java.net.URL; //導入方法依賴的package包/類

/**

*

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.

*

* @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,

示例3: getUrlWithQueryString

​點讚 3

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,

示例4: browse

​點讚 3

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,

示例5: toURI

​點讚 3

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,

示例6: parse

​點讚 3

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 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,

示例7: splitFragmentString

​點讚 3

import java.net.URL; //導入方法依賴的package包/類

public static Map splitFragmentString(String urlString) {

try {

URL url = new URL(urlString);

Map 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,

示例8: removeInstitution

​點讚 3

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,

示例9: toExternalForm

​點讚 2

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,

示例10: encodeUrl

​點讚 2

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,

示例11: createExternalURL

​點讚 2

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 jar: 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,

示例12: relativizeElement

​點讚 2

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,

示例13: toExternalForm

​點讚 2

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,

示例14: toExternalForm

​點讚 2

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,

示例15: getWebResponse

​點讚 2

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 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,

示例16: importFileList

​點讚 2

import java.net.URL; //導入方法依賴的package包/類

private boolean importFileList(String fileListString) {

String entries[] = fileListString.split("\r\n");

AbstractProfileBase srcProfile = ProfileManager

.getProfileByName(FileSystemProfile.LOCAL_FILESYSTEM_PROFILE.getName());

AbstractProfileBase destProfile = profilePanel.getSelectedProfile();

String sourcePath = null;

String targetPath = profilePanel.getCurrentDirectory().getPath();

List fileList = new ArrayList();

for (String escapedEntry : entries) {

// Entity encode plus or it'll be reinterpreted as a space character

// They weren't escaped properly in entries...

String entry = URLDecoder.decode(escapedEntry.replace("+", "%2B"));

try {

URL url = new URL(entry);

String pathname = url.getPath();

// You can have neither a query nor ref, just a query, just a ref or a query then a

// ref. A query cannot

// follow a ref. Queries are preceded by a question mark and refs by an octothorp.

// Handle if there was a question mark in the path

if (url.getQuery() != null) {

pathname = pathname + "?" + url.getQuery();

}

// Handle if there was an octothorp in the path

if (url.getRef() != null) {

pathname = pathname + "#" + url.getRef();

}

File sourceFile = new File(pathname);

String filename = sourceFile.getName();

if (sourcePath == null) {

sourcePath = sourceFile.getParent() + File.separatorChar;

}

FileMetadata fileMetaData = new FileMetadata();

if (sourceFile.isDirectory()) {

fileMetaData.setFileType(FileType.DIRECTORY);

pathname += File.separatorChar;

}

ArcMoverFile moverFile = ArcMoverFile.getFileInstance(srcProfile, pathname,

fileMetaData);

ArcCopyFile arcCopyFile = new ArcCopyFile(moverFile, destProfile,

targetPath + filename);

fileList.add(arcCopyFile);

} catch (MalformedURLException urlEx) {

LOG.log(Level.WARNING,

"Unexpected exception attempting to drag and drop fileListString="

+ fileListString,

urlEx);

displayDropLocation("Error when trying to handle " + entry);

return false;

}

}

return runCopyJob(srcProfile, sourcePath, destProfile, targetPath, fileList);

}

開發者ID:Hitachi-Data-Systems,項目名稱:Open-DM,代碼行數:59,

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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值