本文整理了Java中org.restlet.data.Reference
类的一些代码示例,展示了Reference
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Reference
类的具体详情如下:
包路径:org.restlet.data.Reference
类名称:Reference
[英]Reference to a Uniform Resource Identifier (URI). Contrary to the java.net.URI class, this interface represents mutable references. It strictly conforms to the RFC 3986 specifying URIs and follow its naming conventions.
URI reference = absolute-reference | relative-reference
absolute-reference = scheme ":" scheme-specific-part [ "#" fragment ]
scheme-specific-part = ( hierarchical-part [ "?" query ] ) | opaque-part
hierarchical-part = ( "//" authority path-abempty ) | path-absolute | path-rootless | path-empty
authority = [ user-info "@" ] host-domain [ ":" host-port ]
relative-reference = relative-part [ "?" query ] [ "#" fragment ]
relative-part = ( "//" authority path-abempty ) | path-absolute | path-noscheme | path-empty
path-abempty = begins with "/" or is empty
path-absolute = begins with "/" but not "//"
path-noscheme = begins with a non-colon segment
path-rootless = begins with a segment
path-empty = zero characters
Note that this class doesn't encode or decode the reserved characters. It assumes that the URIs or the URI parts passed in are properly encoded using the standard URI encoding mechanism. You can use the static "encode()" and "decode()" methods for this purpose. Note that if an invalid URI character is detected by the constructor or one of the setters, a trace will be logged and the character will be automatically encoded.
The fundamental point to underline is the difference between an URI "reference" and an URI. Contrary to an URI (the target identifier of a REST resource), an URI reference can be relative (with or without query and fragment part). This relative URI reference can then be resolved against a base reference via the getTargetRef() method which will return a new resolved Reference instance, an absolute URI reference with no base reference and with no dot-segments (the path segments "." and "..").
You can also apply the getTargetRef() method on absolute references in order to solve the dot-segments. Note that applying the getRelativeRef() method on an absolute reference returns the current reference relatively to a base reference, if any, and solves the dot-segments.
The Reference stores its data as a single string, the one passed to the constructor. This string can always be obtained using the toString() method. A couple of integer indexes are maintained to improve the extraction time of various reference properties (URI components).
When you modify a specific component of the URI reference, via the setPath() method for example, the internal string is simply regenerated by updating only the relevant part. We try as much as possible to protect the bytes given to the Reference class instead of transparently parsing and normalizing the URI data. Our idea is to protect encodings and special characters in all case and reduce the memory size taken by this class while making Reference instances mutable.
Because the base reference is only a property of the Reference ("baseRef"). When you use the "Reference(base, path)" constructor, it is equivalent to doing:
ref = new Reference(path);
ref.setBaseRef(base);
The base ref is not automatically resolved or "merged" with the rest of the reference information (the path here). For example, this let's you reuse a single reference as the base of several relative references. If you modify the base reference, all relative references are still accurate.
Note that the name and value properties are thread safe, stored in volatile members.
[中]对统一资源标识符(URI)的引用。与java相反。网URI类,此接口表示可变引用。它严格遵守RFC 3986指定URI并遵循其命名约定。
URI reference = absolute-reference | relative-reference
absolute-reference = scheme ":" scheme-specific-part [ "#" fragment ]
scheme-specific-part = ( hierarchical-part [ "?" query ] ) | opaque-part
hierarchical-part = ( "//" authority path-abempty ) | path-absolute | path-rootless | path-empty
authority = [ user-info "@" ] host-domain [ ":" host-port ]
relative-reference = relative-part [ "?" query ] [ "#" fragment ]
relative-part = ( "//" authority path-abempty ) | path-absolute | path-noscheme | path-empty
path-abempty = begins with "/" or is empty
path-absolute = begins with "/" but not "//"
path-noscheme = begins with a non-colon segment
path-rootless = begins with a segment
path-empty = zero characters
请注意,此类不会对保留字符进行编码或解码。它假设传入的URI或URI部分使用标准URI编码机制进行了正确编码。为此,可以使用静态的“encode()”和“decode()”方法。请注意,如果构造函数或setter之一检测到无效的URI字符,将记录一个跟踪,并自动对该字符进行编码。
要强调的基本点是URI“引用”和URI之间的区别。与URI(REST资源的目标标识符)相反,URI引用可以是相对的(带或不带查询和片段部分)。然后,可以通过getTargetRef()方法根据基引用解析此相对URI引用,该方法将返回一个新的已解析引用实例,即没有基引用且没有点段(路径段)的绝对URI引用和“.”。
还可以对绝对引用应用getTargetRef()方法,以求解点段。请注意,对绝对引用应用getRelativeRef()方法将返回相对于基引用(如果有)的当前引用,并求解点段。
引用将其数据存储为单个字符串,即传递给构造函数的字符串。此字符串始终可以使用toString()方法获得。维护了几个整数索引,以缩短各种引用属性(URI组件)的提取时间。
例如,通过setPath()方法修改URI引用的特定组件时,只需更新相关部分即可重新生成内部字符串。我们尽可能地保护提供给引用类的字节,而不是透明地解析和规范化URI数据。我们的想法是在所有情况下保护编码和特殊字符,并减少此类占用的内存大小,同时使引用实例可变。
因为基本引用只是引用(“baseRef”)的一个属性。使用“Reference(base,path)”构造函数时,相当于执行以下操作:
ref=新参考(路径);
ref.setBaseRef(基础);
基本参考不会自动解析或与其他参考信息(此处的路径)“合并”。例如,这样可以重用单个引用作为多个相对引用的基础。如果修改基准参照,所有相对参照仍然准确。
注意,name和value属性是线程安全的,存储在volatile成员中。
代码示例来源:origin: internetarchive/heritrix3
/**
* Constructs a nested Map data structure with the information represented
* by this Resource. The result is particularly suitable for use with with
* {@link XmlMarshaller}.
*
* @return the nested Map data structure
*/
protected ScriptModel makeDataModel() {
String baseRef = getRequest().getResourceRef().getBaseRef().toString();
if(!baseRef.endsWith("/")) {
baseRef += "/";
}
Reference baseRefRef = new Reference(baseRef);
ScriptModel model = new ScriptModel(scriptingConsole,
new Reference(baseRefRef, "..").getTargetRef().toString(),
getAvailableScriptEngines());
return model;
}
代码示例来源:origin: internetarchive/heritrix3
public List<Variant> getVariants() {
List<Variant> variants = super.getVariants();
Form f = getRequest().getResourceRef().getQueryAsForm();
String format = f.getFirstValue("format");
if("textedit".equals(format)) {
if(variants.isEmpty()) {
FileRepresentation)v,
this,
f.getFirstValue("pos"),
f.getFirstValue("lines"),
f.getFirstValue("reverse")));
};
代码示例来源:origin: internetarchive/heritrix3
Reference baseRef = getRequest().getResourceRef().getBaseRef();
if (baseRef.getPath().endsWith("beans")) {
baseRef.setPath(baseRef.getPath() + "/");
bean.put("url", new Reference(baseRef, "../beans/" + getBeanToNameMap().get(obj)).getTargetRef());
bean.put("class", obj.getClass().getName());
代码示例来源:origin: internetarchive/heritrix3
/**
* Constructs a nested Map data structure with the information represented
* by this Resource. The result is particularly suitable for use with with
* {@link XmlMarshaller}.
*
* @return the nested Map data structure
*/
protected CrawlJobModel makeDataModel() {
String baseRef = getRequest().getResourceRef().getBaseRef().toString();
if (!baseRef.endsWith("/")) {
baseRef += "/";
}
return new CrawlJobModel(cj,baseRef);
}
代码示例来源:origin: internetarchive/heritrix3
/**
* Construct navigational URI for given parameters.
*
* @param pos desired position in file
* @param lines desired signed line count
* @param reverse if line ordering should be displayed in reverse
* @return String URI appropriate to navigate to desired view
*/
protected String getControlUri(long pos, int lines, boolean reverse) {
Form query = new Form();
query.add("format","paged");
if(pos!=0) {
query.add("pos", Long.toString(pos));
}
if(lines!=128) {
if(Math.abs(lines)<1) {
lines = 1;
}
query.add("lines",Integer.toString(lines));
}
if(reverse) {
query.add("reverse","y");
}
Reference viewRef = dirResource.getRequest().getOriginalRef().clone();
viewRef.setQuery(query.getQueryString());
return viewRef.toString();
}
}
代码示例来源:origin: org.restlet.jee/org.restlet.ext.net
@Override
public void handle(Request request, Response response) {
try {
if (Protocol.FTP.equals(request.getProtocol())) {
if (Method.GET.equals(request.getMethod())) {
Reference ftpRef = request.getResourceRef();
String userInfo = null;
ftpRef.setUserInfo(userInfo);
URL url = ftpRef.toUrl();
URLConnection connection = url.openConnection();
.setAllowUserInteraction(isAllowUserInteraction());
connection.setUseCaches(isUseCaches());
response.setEntity(new InputRepresentation(connection
.getInputStream()));
Entity.updateMetadata(request.getResourceRef().getPath(),
response.getEntity(), true, getMetadataService());
} else {
getLogger()
response.setStatus(Status.CONNECTOR_ERROR_INTERNAL, e.getMessage());
代码示例来源:origin: org.restlet.jee/org.restlet.ext.json
/**
* Assumes that there is a "callback" query parameter available in the URI
* query string, containing the name of the JavaScript callback method.
*/
@Override
public void afterHandle(Request request, Response response) {
// Check the presence of the callback parameter
String callback = request.getResourceRef().getQueryAsForm()
.getFirstValue("callback");
if (callback != null) {
Representation entity = response.getEntity();
if (entity != null
&& ("text".equals(entity.getMediaType().getMainType()) || MediaType.APPLICATION_JSON
.equals(entity.getMediaType()))) {
response.setEntity(new JsonpRepresentation(callback, response
.getStatus(), response.getEntity()));
response.setStatus(Status.SUCCESS_OK);
}
}
}
代码示例来源:origin: org.metaeffekt.dcc/dcc-agent-core
for (Map.Entry<String, Object> entry : request.getAttributes()
.entrySet()) {
if (!getHeaderFilterStrategy().applyFilterToExternalHeaders(
inMessage.setHeader(Exchange.HTTP_METHOD, request.getMethod());
inMessage.setHeader(Exchange.CONTENT_TYPE, request.getEntity()
.getMediaType());
String query = request.getResourceRef().getQuery();
Request httpRequest = (Request) request;
if (httpRequest.getHostRef() != null) {
String host = httpRequest.getHostRef().getHostDomain();
int port = httpRequest.getHostRef().getHostPort();
String protocol = "http";
if (httpRequest.getHostRef().getSchemeProtocol() != null) {
protocol = httpRequest.getHostRef().getSchemeProtocol().getSchemeName();
inMessage.setHeader(Exchange.HTTP_URI, httpRequest.getOriginalRef().getPath());
Form form = new Form(query);
if (form != null) {
for (Map.Entry<String, String> entry : form.getValuesMap()
.entrySet()) {
代码示例来源:origin: org.restlet.android/org.restlet.ext.xml
Reference baseRef = new Reference(base);
targetRef = new Reference(baseRef, href);
} else {
targetRef = new Reference(href);
String targetUri = targetRef.getTargetRef().toString();
Response response = this.context.getClientDispatcher().handle(
new Request(Method.GET, targetUri));
if (response.getStatus().isSuccess()
&& response.isEntityAvailable()) {
try {
result = new StreamSource(response.getEntity().getStream());
result.setSystemId(targetUri);
代码示例来源:origin: org.restlet.jse/org.restlet.example
@Override
protected int beforeHandle(Request request, Response response) {
Cookie cookie = request.getCookies().getFirst("Credentials");
if (cookie != null) {
// Extract the challenge response from the cookie
String[] credentials = cookie.getValue().split("=");
if (credentials.length == 2) {
String identifier = credentials[0];
String secret = credentials[1];
request.setChallengeResponse(new ChallengeResponse(
ChallengeScheme.HTTP_COOKIE, identifier, secret));
}
} else if (Method.POST.equals(request.getMethod())
&& request.getResourceRef().getQueryAsForm().getFirst("login") != null) {
// Intercepting a login form
Form credentials = new Form(request.getEntity());
String identifier = credentials.getFirstValue("identifier");
String secret = credentials.getFirstValue("secret");
request.setChallengeResponse(new ChallengeResponse(
ChallengeScheme.HTTP_COOKIE, identifier, secret));
// Continue call processing to return the target representation if
// authentication is successful or a new login page
request.setMethod(Method.GET);
}
return super.beforeHandle(request, response);
}
代码示例来源:origin: org.restlet.jee/org.restlet.ext.httpclient
/**
* Creates a low-level HTTP client call from a high-level uniform call.
*
* @param request
* The high-level request.
* @return A low-level HTTP client call.
*/
@Override
public ClientCall create(Request request) {
ClientCall result = null;
try {
result = new HttpMethodCall(this, request.getMethod().toString(),
ReferenceUtils.update(request.getResourceRef(), request)
.toString(), request.isEntityAvailable());
} catch (IOException ioe) {
getLogger().log(Level.WARNING,
"Unable to create the HTTP client call", ioe);
}
return result;
}
代码示例来源:origin: org.apache.polygene.libraries/org.apache.polygene.library.rest-server
private boolean shouldShowCommandForm( Method interactionMethod )
{
// Show form on GET/HEAD
if( Request.getCurrent().getMethod().isSafe() )
{
return true;
}
if( interactionMethod.getParameterTypes().length > 0 )
{
return !( interactionMethod.getParameterTypes()[ 0 ].equals( Response.class ) || Request.getCurrent()
.getEntity()
.isAvailable() || Request.getCurrent().getEntityAsText() != null || Request.getCurrent()
.getResourceRef()
.getQuery() != null );
}
return false;
}
代码示例来源:origin: org.sonatype.nexus/nexus-it-helper-plugin
public Object get(Context context, Request request, Response response, Variant variant)
throws ResourceException
{
Form form = request.getResourceRef().getQueryAsForm();
final long timeout = Long.parseLong(form.getFirstValue("timeout", "60000"));
try {
final long startTime = System.currentTimeMillis();
while (System.currentTimeMillis() - startTime <= timeout) {
if (!((ManagerImpl) manager).isUpdatePrefixFileJobRunning()) {
response.setStatus(Status.SUCCESS_OK);
return "Ok";
}
Thread.sleep(500);
}
}
catch (final InterruptedException ignore) {
// ignore
}
response.setStatus(Status.SUCCESS_ACCEPTED);
return "Still munching on them...";
}
}
代码示例来源:origin: org.restlet.osgi/org.restlet
ClientInfo clientInfo = request.getClientInfo();
addHeader(HEADER_FROM, request.getClientInfo().getFrom(), headers);
Reference hostRef = (request.getResourceRef().getBaseRef() != null) ? request
.getResourceRef().getBaseRef() : request.getResourceRef();
if (hostRef.getHostDomain() != null) {
String host = hostRef.getHostDomain();
int hostRefPortValue = hostRef.getHostPort();
&& (hostRefPortValue != request.getProtocol().getDefaultPort())) {
host = host + ':' + hostRefPortValue;
if (request.getReferrerRef() != null) {
addHeader(HEADER_REFERRER, request.getReferrerRef().toString(), headers);
if (request.getAccessControlRequestMethod() != null) {
addHeader(HEADER_ACCESS_CONTROL_REQUEST_METHOD,
request.getAccessControlRequestMethod().getName(), headers);
代码示例来源:origin: org.restlet.jee/org.restlet.ext.jaxrs
super.handle(request, response);
ResourceObject resourceObject = null;
final Reference baseRef = request.getResourceRef().getBaseRef();
request.setRootRef(new Reference(baseRef.toString()));
Representation entity = request.getEntity();
if (entity != null)
entity.release();
代码示例来源:origin: ontopia/ontopia
protected void redirectTo(TMO object) {
Reference baseRef = getRequest().getResourceRef().getBaseRef();
if (!baseRef.getLastSegment().endsWith("/")) {
baseRef = new Reference(baseRef.toString() + "/");
}
// todo: maybe this should be '302 Found' instead
redirectSeeOther(new Reference(baseRef, object.getObjectId()).getTargetRef());
}
}
代码示例来源:origin: org.codeartisans.qipki/qipki-ca-http
protected final String getQueryParamValue( String key, String defaultValue )
{
String value = getRequest().getResourceRef().getQueryAsForm().getFirstValue( key );
if ( Strings.isEmpty( value ) ) {
value = defaultValue;
}
return value;
}
代码示例来源:origin: com.github.ansell.oas/oas-webservice-impl
final String username = this.getRequest().getResourceRef().getQueryAsForm().getFirstValue("username");
this.getResponse().setStatus(Status.SUCCESS_NO_CONTENT, "User deleted");
代码示例来源:origin: org.sonatype.nexus/nexus-rest-api
protected boolean isRemote( Request request, String resourceStorePath )
{
// check do we need remote only access
boolean isRemote = request.getResourceRef().getQueryAsForm().getFirst( IS_REMOTE_PARAMETER ) != null;
return isRemote;
}
代码示例来源:origin: org.restlet.android/org.restlet.ext.atom
/**
* Returns the feed representation.
*
* @return The feed representation.
* @throws Exception
*/
public Feed getFeed() throws Exception {
final Reference feedRef = getHref();
if (feedRef.isRelative()) {
feedRef.setBaseRef(getWorkspace().getService().getReference());
}
final Request request = new Request(Method.GET, feedRef.getTargetRef());
final Response response = getWorkspace().getService()
.getClientDispatcher().handle(request);
if (response.getStatus().equals(Status.SUCCESS_OK)) {
return new Feed(response.getEntity());
}
throw new Exception(
"Couldn't get the feed representation. Status returned: "
+ response.getStatus());
}
内容来源于网络,如有侵权,请联系作者删除!