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

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

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

Reference.setPath介绍

[英]Sets the path component for hierarchical identifiers.
[中]设置层次标识符的路径组件。

代码示例

代码示例来源:origin: internetarchive/heritrix3

baseRef.setPath(baseRef.getPath() + "/");

代码示例来源:origin: internetarchive/heritrix3

public void acceptRepresentation(Representation entity) throws ResourceException {
  if (appCtx == null) {
    throw new ResourceException(404);
  }
  // copy op?
  Form form = getRequest().getEntityAsForm();
  beanPath = form.getFirstValue("beanPath");
  
  String newVal = form.getFirstValue("newVal");
  if(newVal!=null) {
    int i = beanPath.indexOf(".");
    String beanName = i<0?beanPath:beanPath.substring(0,i);
    Object namedBean = appCtx.getBean(beanName);
    BeanWrapperImpl bwrap = new BeanWrapperImpl(namedBean);
    String propPath = beanPath.substring(i+1);
    Object coercedVal = bwrap.convertIfNecessary(newVal, bwrap.getPropertyValue(propPath).getClass()); 
    bwrap.setPropertyValue(propPath, coercedVal);
  }
  Reference ref = getRequest().getResourceRef();
  ref.setPath(getBeansRefPath());
  ref.addSegment(beanPath);
  getResponse().redirectSeeOther(ref);
}

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

/**
 * Sets the segments of a hierarchical path.<br>
 * A new absolute path will replace any existing one.
 * 
 * @param segments
 *            The segments of the hierarchical path.
 */
public void setSegments(List<String> segments) {
  final StringBuilder sb = new StringBuilder();
  for (final String segment : segments) {
    sb.append('/').append(segment);
  }
  setPath(sb.toString());
}

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

/**
 * Sets the segments of a hierarchical path.<br>
 * A new absolute path will replace any existing one.
 * 
 * @param segments
 *            The segments of the hierarchical path.
 */
public void setSegments(List<String> segments) {
  final StringBuilder sb = new StringBuilder();
  for (final String segment : segments) {
    sb.append('/').append(segment);
  }
  setPath(sb.toString());
}

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

/**
 * Sets the segments of a hierarchical path.<br>
 * A new absolute path will replace any existing one.
 * 
 * @param segments
 *            The segments of the hierarchical path.
 */
public void setSegments(List<String> segments) {
  final StringBuilder sb = new StringBuilder();
  for (final String segment : segments) {
    sb.append('/').append(segment);
  }
  setPath(sb.toString());
}

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

/**
 * Sets the last segment of the path. If no path is available, then it
 * creates one and adds a slash in front of the given last segmetn. <br>
 * Note that no URI decoding is done by this method.
 * 
 * @param lastSegment
 *            The last segment of a hierarchical path.
 */
public void setLastSegment(String lastSegment) {
  final String path = getPath();
  final int lastSlashIndex = path.lastIndexOf('/');
  if (lastSlashIndex != -1) {
    setPath(path.substring(0, lastSlashIndex + 1) + lastSegment);
  } else {
    setPath('/' + lastSegment);
  }
}

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

/**
 * Sets the last segment of the path. If no path is available, then it
 * creates one and adds a slash in front of the given last segmetn. <br>
 * Note that no URI decoding is done by this method.
 * 
 * @param lastSegment
 *            The last segment of a hierarchical path.
 */
public void setLastSegment(String lastSegment) {
  String path = getPath();
  int lastSlashIndex = -1;
  if (path != null) {
    lastSlashIndex = path.lastIndexOf('/');
  }
  if (lastSlashIndex != -1) {
    setPath(path.substring(0, lastSlashIndex + 1) + lastSegment);
  } else {
    setPath('/' + lastSegment);
  }
}

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

/**
 * Sets the last segment of the path. If no path is available, then it
 * creates one and adds a slash in front of the given last segmetn. <br>
 * Note that no URI decoding is done by this method.
 * 
 * @param lastSegment
 *            The last segment of a hierarchical path.
 */
public void setLastSegment(String lastSegment) {
  String path = getPath();
  if (path != null) {
    int lastSlashIndex = path.lastIndexOf('/');
    if (lastSlashIndex != -1) {
      setPath(path.substring(0, lastSlashIndex + 1) + lastSegment);
      return;
    }
  }
  setPath('/' + lastSegment);
}

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

/**
 * Adds a segment at the end of the path. If the current path doesn't end
 * with a slash character, one is inserted before the new segment value. The
 * value is automatically encoded if necessary.
 * 
 * @param value
 *            The segment value to add.
 * @return The updated reference.
 */
public Reference addSegment(String value) {
  final String path = getPath();
  if (value != null) {
    if (path == null) {
      setPath("/" + value);
    } else if (path.endsWith("/")) {
      setPath(path + encode(value));
    } else {
      setPath(path + "/" + encode(value));
    }
  }
  return this;
}

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

/**
 * Adds a segment at the end of the path. If the current path doesn't end
 * with a slash character, one is inserted before the new segment value. The
 * value is automatically encoded if necessary.
 * 
 * @param value
 *            The segment value to add.
 * @return The updated reference.
 */
public Reference addSegment(String value) {
  final String path = getPath();
  if (value != null) {
    if (path == null) {
      setPath("/" + value);
    } else {
      if (path.endsWith("/")) {
        setPath(path + encode(value));
      } else {
        setPath(path + "/" + encode(value));
      }
    }
  }
  return this;
}

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

private void setRequestPathToAnnotationPath(Method javaMethod,
    Request request) {
  Path methodPathAnnotation = javaMethod.getAnnotation(Path.class);
  if (methodPathAnnotation != null) {
    String methodPath = methodPathAnnotation.value();
    if (!StringUtils.isNullOrEmpty(methodPath)) {
      String fullUriFromPath = request.getResourceRef().getPath();
      if (fullUriFromPath.endsWith("/")) {
        if (methodPath.startsWith("/")) {
          fullUriFromPath += methodPath.substring(1);
        } else {
          fullUriFromPath += methodPath;
        }
      } else {
        if (methodPath.startsWith("/")) {
          fullUriFromPath += methodPath;
        } else {
          fullUriFromPath += "/" + methodPath;
        }
      }
      request.getResourceRef().setPath(fullUriFromPath);
    }
  }
}

代码示例来源:origin: apache/attic-polygene-java

public synchronized ContextResourceClient newClient( String relativePath )
{
  if( relativePath.startsWith( "http://" ) )
  {
    return contextResourceFactory.newClient( new Reference( relativePath ) );
  }
  Reference reference = this.reference.clone();
  if( relativePath.startsWith( "/" ) )
  {
    reference.setPath( relativePath );
  }
  else
  {
    reference.setPath( reference.getPath() + relativePath );
    reference = reference.normalize();
  }
  return contextResourceFactory.newClient( reference );
}

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

private Reference updateBaseRefPath(Reference reference) {
 if (reference.getBaseRef().getPath() == null) {
  reference.getBaseRef().setPath("/");
 }
 else if (!reference.getBaseRef().getPath().endsWith("/")) {
  reference.getBaseRef().setPath(reference.getBaseRef().getPath() + "/");
 }
 return reference;
}

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

private Reference updateBaseRefPath( Reference reference )
{
  if ( reference.getBaseRef().getPath() == null )
  {
    reference.getBaseRef().setPath( "/" );
  }
  else if ( !reference.getBaseRef().getPath().endsWith( "/" ) )
  {
    reference.getBaseRef().setPath( reference.getBaseRef().getPath() + "/" );
  }
  return reference;
}

代码示例来源:origin: org.codeartisans.qipki/qipki-ca-http

@Override
protected int beforeHandle( Request request, Response response )
{
  String extensions = request.getResourceRef().getExtensions();
  if ( extensions != null ) {
    int idx = extensions.lastIndexOf( '.' );
    if ( idx != -1 ) {
      extensions = extensions.substring( idx + 1 );
    }
    MetadataService metadataService = getApplication().getMetadataService();
    Metadata metadata = metadataService.getMetadata( extensions );
    if ( metadata instanceof MediaType ) {
      request.getClientInfo().setAcceptedMediaTypes( Collections.singletonList( new Preference<MediaType>( ( MediaType ) metadata ) ) );
      String path = request.getResourceRef().getPath();
      path = path.substring( 0, path.length() - extensions.length() - 1 );
      request.getResourceRef().setPath( path );
    }
  }
  return Filter.CONTINUE;
}

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

protected Reference createRootReference(Request request, String relPart) {
 Reference ref = new Reference(getContextRoot(request), relPart);
 if (!ref.getBaseRef().getPath().endsWith("/")) {
  ref.getBaseRef().setPath(ref.getBaseRef().getPath() + "/");
 }
 return ref.getTargetRef();
}

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

@Override
public Reference getContextRoot( Request request )
{
  Reference result = null;
  if ( globalRestApiSettings.isEnabled() && globalRestApiSettings.isForceBaseUrl()
    && StringUtils.isNotEmpty( globalRestApiSettings.getBaseUrl() ) )
  {
    result = new Reference( globalRestApiSettings.getBaseUrl() );
  }
  else
  {
    result = request.getRootRef();
  }
  // fix for when restlet is at webapp root
  if ( StringUtils.isEmpty( result.getPath() ) )
  {
    result.setPath( "/" );
  }
  return result;
}

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

protected Reference createRootReference( Request request, String relPart )
{
  Reference ref = new Reference( getContextRoot( request ), relPart );
  if ( !ref.getBaseRef().getPath().endsWith( "/" ) )
  {
    ref.getBaseRef().setPath( ref.getBaseRef().getPath() + "/" );
  }
  return ref.getTargetRef();
}

代码示例来源: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.archive.heritrix/heritrix-engine

public void acceptRepresentation(Representation entity) throws ResourceException {
  if (appCtx == null) {
    throw new ResourceException(404);
  }
  // copy op?
  Form form = getRequest().getEntityAsForm();
  beanPath = form.getFirstValue("beanPath");
  
  String newVal = form.getFirstValue("newVal");
  if(newVal!=null) {
    int i = beanPath.indexOf(".");
    String beanName = i<0?beanPath:beanPath.substring(0,i);
    Object namedBean = appCtx.getBean(beanName);
    BeanWrapperImpl bwrap = new BeanWrapperImpl(namedBean);
    String propPath = beanPath.substring(i+1);
    Object coercedVal = bwrap.convertIfNecessary(newVal, bwrap.getPropertyValue(propPath).getClass()); 
    bwrap.setPropertyValue(propPath, coercedVal);
  }
  Reference ref = getRequest().getResourceRef();
  ref.setPath(getBeansRefPath());
  ref.addSegment(beanPath);
  getResponse().redirectSeeOther(ref);
}

相关文章

微信公众号

最新文章

更多

Reference类方法