org.restlet.data.Reference.getParentRef()方法的使用及代码示例

x33g5p2x  于2022-01-28 转载在 其他  
字(11.1k)|赞(0)|评价(0)|浏览(82)

本文整理了Java中org.restlet.data.Reference.getParentRef方法的一些代码示例,展示了Reference.getParentRef的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Reference.getParentRef方法的具体详情如下:
包路径:org.restlet.data.Reference
类名称:Reference
方法名:getParentRef

Reference.getParentRef介绍

[英]Returns the parent reference of a hierarchical reference. The last slash of the path will be considered as the end of the parent path.
[中]返回分层引用的父引用。路径的最后一条斜线将被视为父路径的终点。

代码示例

代码示例来源:origin: org.geoserver/rest

/**
 * Returns the base url of a request.
 */
public static String getBaseURL( Request request ) {
  Reference ref = request.getResourceRef();
  HttpServletRequest servletRequest = getServletRequest(request);
  if ( servletRequest != null ) {
    String baseURL = ref.getIdentifier();
    return baseURL.substring(0, baseURL.length()-servletRequest.getPathInfo().length());
  } else {
    return ref.getParentRef().getIdentifier();
  }
}

代码示例来源:origin: org.geowebcache/gwc-rest

private void doGet(Request request, Response response) {
    Reference resourceRef = request.getResourceRef();
    String baseUrl = resourceRef.toString();
    if (baseUrl.endsWith("/")) {
      baseUrl = baseUrl.substring(0, baseUrl.length() - 1);
    }
    Representation result = new StringRepresentation(
        "<html><body>\n"
            + "<a id=\"logo\" href=\""
            + resourceRef.getParentRef()
            + "\">"
            + "<img src=\""
            + baseUrl
            + "/web/geowebcache_logo.png\" alt=\"\" height=\"100\" width=\"353\" border=\"0\"/></a>\n"
            + "<h3>Resources available from here:</h3>"
            + "<ul>"
            + "<li><h4><a href=\""
            + baseUrl
            + "/layers/\">layers</a></h4>"
            + "Lets you see the configured layers. You can also view a specific layer "
            + " by appending the name of the layer to the URL, DELETE an existing layer "
            + " or POST a new one. Note that the latter operations only make sense when GeoWebCache"
            + " has been configured through geowebcache.xml. You can POST either XML or JSON."
            + "</li>\n" + "<li><h4>seed</h4>" + "" + "</li>\n" + "</ul>"
            + "</body></html>",

        MediaType.TEXT_HTML);
    response.setEntity(result);
  }
}

代码示例来源:origin: org.sonatype.nexus.plugins/nexus-restlet1x-plugin

@Override
public Reference getContextRoot(Request request) {
 Reference result = null;
 if (globalRestApiSettings.isEnabled() && globalRestApiSettings.isForceBaseUrl()
   && StringUtils.isNotEmpty(globalRestApiSettings.getBaseUrl())) {
  result = new Reference(globalRestApiSettings.getBaseUrl());
 }
 else {
  // TODO: NEXUS-6045 hack, Restlet app root is now "/service/local", so going up 2 levels!
  result = request.getRootRef().getParentRef().getParentRef();
 }
 // fix for when restlet is at webapp root
 if (StringUtils.isEmpty(result.getPath())) {
  result.setPath("/");
 }
 return result;
}

代码示例来源:origin: org.geowebcache/gwc-rest

/**
 * GET outputs an existing layer
 * 
 * @param req
 * @param resp
 * @throws RestletException
 * @throws
 */
protected void doGet(Request req, Response resp) throws RestletException {
  String layerName = (String) req.getAttributes().get("layer");
  final String formatExtension = (String) req.getAttributes().get("extension");
  Representation representation;
  if (layerName == null) {
    String restRoot = req.getResourceRef().getParentRef().toString();
    if (restRoot.endsWith("/")) {
      restRoot = restRoot.substring(0, restRoot.length() - 1);
    }
    representation = listLayers(formatExtension, restRoot);
  } else {
    try {
      layerName = URLDecoder.decode(layerName, "UTF-8");
    } catch (UnsupportedEncodingException uee) {
    }
    representation = doGetInternal(layerName, formatExtension);
  }
  resp.setEntity(representation);
}

代码示例来源:origin: org.restlet.osgi/org.restlet

/**
 * Returns a representation of the list in "text/html" format.
 * 
 * @return A representation of the list in "text/html" format.
 */
public Representation getWebRepresentation() {
  // Create a simple HTML list
  final StringBuilder sb = new StringBuilder();
  sb.append("<html><body style=\"font-family: sans-serif;\">\n");
  if (getIdentifier() != null) {
    sb.append("<h2>Listing of \"" + getIdentifier().getPath()
        + "\"</h2>\n");
    final Reference parentRef = getIdentifier().getParentRef();
    if (!parentRef.equals(getIdentifier())) {
      sb.append("<a href=\"" + parentRef + "\">..</a><br>\n");
    }
  } else {
    sb.append("<h2>List of references</h2>\n");
  }
  for (final Reference ref : this) {
    sb.append("<a href=\"" + ref.toString() + "\">"
        + ref.getRelativeRef(getIdentifier()) + "</a><br>\n");
  }
  sb.append("</body></html>\n");
  return new StringRepresentation(sb.toString(), MediaType.TEXT_HTML);
}

代码示例来源:origin: org.restlet/org.restlet

/**
 * Returns a representation of the list in "text/html" format.
 * 
 * @return A representation of the list in "text/html" format.
 */
public Representation getWebRepresentation() {
  // Create a simple HTML list
  final StringBuilder sb = new StringBuilder();
  sb.append("<html><body>\n");
  if (getIdentifier() != null) {
    sb.append("<h2>Listing of \"" + getIdentifier().getPath()
        + "\"</h2>\n");
    final Reference parentRef = getIdentifier().getParentRef();
    if (!parentRef.equals(getIdentifier())) {
      sb.append("<a href=\"" + parentRef + "\">..</a><br>\n");
    }
  } else {
    sb.append("<h2>List of references</h2>\n");
  }
  for (final Reference ref : this) {
    sb.append("<a href=\"" + ref.toString() + "\">"
        + ref.getRelativeRef(getIdentifier()) + "</a><br>\n");
  }
  sb.append("</body></html>\n");
  return new StringRepresentation(sb.toString(), MediaType.TEXT_HTML);
}

代码示例来源:origin: DeviceConnect/DeviceConnect-Android

/**
 * Returns a representation of the list in "text/html" format.
 * 
 * @return A representation of the list in "text/html" format.
 */
public Representation getWebRepresentation() {
  // Create a simple HTML list
  final StringBuilder sb = new StringBuilder();
  sb.append("<html><body style=\"font-family: sans-serif;\">\n");
  if (getIdentifier() != null) {
    sb.append("<h2>Listing of \"" + getIdentifier().getPath()
        + "\"</h2>\n");
    final Reference parentRef = getIdentifier().getParentRef();
    if (!parentRef.equals(getIdentifier())) {
      sb.append("<a href=\"" + parentRef + "\">..</a><br>\n");
    }
  } else {
    sb.append("<h2>List of references</h2>\n");
  }
  for (final Reference ref : this) {
    sb.append("<a href=\"" + ref.toString() + "\">"
        + ref.getRelativeRef(getIdentifier()) + "</a><br>\n");
  }
  sb.append("</body></html>\n");
  return new StringRepresentation(sb.toString(), MediaType.TEXT_HTML);
}

代码示例来源:origin: org.sonatype.nexus.plugins/nexus-restlet1x-plugin

baseURL = Request.getCurrent().getRootRef().getParentRef().getParentRef().toString();

代码示例来源:origin: org.sonatype.nexus.plugins/nexus-restlet1x-plugin

private String getResourceUri(Request req, ContentListResource resource, StorageItem child) {
 // NEXUS-4244: simply force both baseURLs, coming from nexus.xml and extracted from current request
 // to end with slash ("/").
 Reference root = getContextRoot(req);
 if (StringUtils.isBlank(root.getPath()) || !root.getPath().endsWith("/")) {
  root.setPath(StringUtils.defaultString(root.getPath(), "") + "/");
 }
 Reference requestRoot = req.getRootRef().getParentRef().getParentRef();
 if (StringUtils.isBlank(requestRoot.getPath()) || !requestRoot.getPath().endsWith("/")) {
  requestRoot.setPath(StringUtils.defaultString(requestRoot.getPath(), "") + "/");
 }
 final Reference ref = req.getResourceRef().getTargetRef();
 String uri = ref.toString();
 if (ref.getQuery() != null) {
  uri = uri.substring(0, uri.length() - ref.getQuery().length() - 1);
 }
 if (!uri.endsWith("/")) {
  uri += "/";
 }
 uri += child.getName();
 if (!resource.isLeaf()) {
  uri += "/";
 }
 if (root == requestRoot || root.equals(requestRoot)) {
  return uri;
 }
 else {
  return uri.replace(requestRoot.toString(), root.toString());
 }
}

代码示例来源:origin: org.geoserver/rest

String baseURL = request.getRootRef().getParentRef().toString();
String rootPath = request.getRootRef().toString().substring(baseURL.length());
String pagePath = request.getResourceRef().toString().substring(baseURL.length());

代码示例来源:origin: org.restlet.jse/org.restlet.example

/**
 * Remove this resource.
 */
@Delete
public void removeContact() throws ResourceException {
  getObjectsFacade().deleteContact(this.user, this.contact);
  getResponse().redirectSeeOther(
      getRequest().getResourceRef().getParentRef());
}

代码示例来源:origin: org.restlet.jse/org.restlet.example

/**
 * Remove this resource.
 */
@Delete
public void removeUser() throws ResourceException {
  getObjectsFacade().deleteUser(this.user);
  getResponse().redirectSeeOther(
      getRequest().getResourceRef().getParentRef());
}

代码示例来源:origin: org.restlet.osgi/org.restlet

/**
 * Returns the parent resource. The parent resource is defined in the sense
 * of hierarchical URIs. If the resource URI is not hierarchical, then an
 * exception is thrown.
 * 
 * @return The parent resource.
 */
public ClientResource getParent() throws ResourceException {
  ClientResource result = null;
  if (getReference().isHierarchical()) {
    result = new ClientResource(this);
    result.setReference(getReference().getParentRef());
  } else {
    doError(Status.CLIENT_ERROR_BAD_REQUEST, "The resource URI is not hierarchical.");
  }
  return result;
}

代码示例来源:origin: DeviceConnect/DeviceConnect-Android

/**
 * Sets up a new authorization session.
 * 
 * @param redirectUri
 *            The redirection URI.
 */
protected static AuthSession setupAuthSession(RedirectionURI redirectUri) {
  
  getLogger().fine("Base ref = " + getReference().getParentRef());
  AuthSession session = AuthSession.newAuthSession();
  session.setRedirectionURI(redirectUri);
  CookieSetting cs = new CookieSetting(ClientCookieID, session.getId());
  // TODO create a secure mode setting, update all cookies
  // cs.setAccessRestricted(true);
  // cs.setSecure(true);
  getResourceCookieSettings().add(cs);
  getLogger().fine("Setting cookie in SetupSession - " + session.getId());
  getResourceContext().getAttributes().put(session.getId(), session);
  return session;
}

代码示例来源:origin: org.restlet.osgi/org.restlet.ext.oauth

/**
 * Sets up a new authorization session.
 * 
 * @param redirectUri
 *            The redirection URI.
 */
protected AuthSession setupAuthSession(RedirectionURI redirectUri) {
  getLogger().fine("Base ref = " + getReference().getParentRef());
  AuthSession session = AuthSession.newAuthSession();
  session.setRedirectionURI(redirectUri);
  CookieSetting cs = new CookieSetting(ClientCookieID, session.getId());
  // TODO create a secure mode setting, update all cookies
  // cs.setAccessRestricted(true);
  // cs.setSecure(true);
  getCookieSettings().add(cs);
  getLogger().fine("Setting cookie in SetupSession - " + session.getId());
  getContext().getAttributes().put(session.getId(), session);
  return session;
}

代码示例来源:origin: org.sonatype.nexus.plugins/nexus-restlet1x-plugin

resource.setRepositories(getRepositoryRouteMemberRepositoryList(request.getResourceRef().getParentRef(),
  route.getMappedRepositories(), request, route.getId()));

代码示例来源:origin: org.sonatype.nexus/nexus-rest-api

resource.setRepositories( getRepositoryRouteMemberRepositoryList( request.getResourceRef().getParentRef(),
  route.getMappedRepositories(), request, route.getId() ) );

相关文章

Reference类方法