本文整理匯總了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;未經允許,請勿轉載。

.net ref java_Java URL.getRef方法代碼示例相关推荐

  1. isdisposed java_Java Shell.isDisposed方法代碼示例

    本文整理匯總了Java中org.eclipse.swt.widgets.Shell.isDisposed方法的典型用法代碼示例.如果您正苦於以下問題:Java Shell.isDisposed方法的具 ...

  2. rowdata java_Java RowDataUtil.addRowData方法代碼示例

    本文整理匯總了Java中org.pentaho.di.core.row.RowDataUtil.addRowData方法的典型用法代碼示例.如果您正苦於以下問題:Java RowDataUtil.ad ...

  3. drawlinetest.java_Java Graphics2D.setRenderingHint方法代碼示例

    本文整理匯總了Java中java.awt.Graphics2D.setRenderingHint方法的典型用法代碼示例.如果您正苦於以下問題:Java Graphics2D.setRenderingH ...

  4. bls java_Java PairingFactory.getPairing方法代碼示例

    本文整理匯總了Java中it.unisa.dia.gas.plaf.jpbc.pairing.PairingFactory.getPairing方法的典型用法代碼示例.如果您正苦於以下問題:Java ...

  5. newinsets用法java_Java XYPlot.setInsets方法代碼示例

    import org.jfree.chart.plot.XYPlot; //導入方法依賴的package包/類 public static void setTimeSeriesRender(Plot ...

  6. remote_port java_Java HttpServletRequest.getRemotePort方法代碼示例

    import javax.servlet.http.HttpServletRequest; //導入方法依賴的package包/類 public ServletRequestCopy(HttpServ ...

  7. create用法java_Java AcousticEchoCanceler.create方法代碼示例

    import android.media.audiofx.AcousticEchoCanceler; //導入方法依賴的package包/類 @Override public boolean init ...

  8. exhaustion java_Java Player.setExhaustion方法代碼示例

    import org.bukkit.entity.Player; //導入方法依賴的package包/類 /** * Set SamaGamesAPI */ @Override public void ...

  9. java getstringarray_Java AnnotationAttributes.getStringArray方法代碼示例

    本文整理匯總了Java中org.springframework.core.annotation.AnnotationAttributes.getStringArray方法的典型用法代碼示例.如果您正苦 ...

最新文章

  1. ASP.NET 下载文件方式
  2. (转载)php array_merge 和 两数组相加区别
  3. maven+eclipse编译常见问题
  4. Python基础概念_13_常见关键字
  5. DB2表结构DDL脚本导出
  6. Object类 java 1614965390
  7. mysql-可视化软安装过程-navicate
  8. 传智播客 c#_播客#46:Alexander Kallaway
  9. [转]UpdatePanel的用法详解
  10. Mac下升级python2.7到python3.6,删除2.7,或者不删除2.7都行
  11. php+select为空,SELECT时候,如何处理某字段空值?
  12. STM32——HAL版——串口发送字符串函数
  13. python美女源代码_python程序员爬取百套美女写真集,同样是爬虫,他为何如此突出...
  14. 乐优商城(11)--用户中心
  15. chrome浏览器debug vue项目,跳过vue源码
  16. 值得推荐的Vue 移动端UI框架
  17. 关于Android Handler同步屏障那些事
  18. 骁龙780G和麒麟990哪个好
  19. 第十六章 - 垃圾回收相关概念
  20. 简单测试IP地址连通性

热门文章

  1. R语言绘图-gganimate 让你的统计图动起来
  2. 模拟双色球彩彩票开奖和购买兑换。红色[1-33]选择6个不重复,蓝色[1-16]选择1个
  3. 魔兽电影这么火,做成游戏一定很多人玩吧
  4. LDO使用之热阻考虑
  5. VC浏览器相关的学习(七)(BHO捕获鼠标键盘事件)
  6. DZ先生怪谈国标之云台控制流程
  7. [QT学习]-调色板|选择文件
  8. 萤石云视频平台播放地址获取demo
  9. 华为harmonyos2,华为官方发布HarmonyOS2
  10. 嫁给通信旺的16条理由!!!